homebridge-hilo
Version:
Plugin Homebridge (non officiel) pour la passerelle et les appareils Hilo de Hydro-Québec | Unofficial Homebridge plugin for Hydro-Québec Hilo bridge and devices
46 lines • 2.12 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Outlet = void 0;
const axios_1 = __importDefault(require("axios"));
const HiloDevice_1 = require("./HiloDevice");
const hiloApi_1 = require("../hiloApi");
class Outlet extends HiloDevice_1.HiloDevice {
constructor(accessory, api) {
super(accessory, api);
this.service =
accessory.getService(this.api.hap.Service.Outlet) ||
accessory.addService(this.api.hap.Service.Outlet);
this.service.setCharacteristic(this.api.hap.Characteristic.Name, this.accessory.context.device.name);
this.service
.getCharacteristic(this.api.hap.Characteristic.On)
.onSet(this.setOn.bind(this))
.onGet(this.getOn.bind(this));
}
updateDevice(device) {
var _a, _b;
super.updateDevice(device);
if ("state" in device) {
(_b = (_a = this.service) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.api.hap.Characteristic.On)) === null || _b === void 0 ? void 0 : _b.updateValue(device.state === "ON");
}
}
async setOn(value) {
var _a;
const on = value;
this.logger.debug(`Setting ${this.accessory.context.device.name} ${on ? "on" : "off"}`);
try {
await hiloApi_1.hiloApi.put(`/Automation/v1/api/Locations/${this.accessory.context.device.locationId}/Devices/${this.accessory.context.device.id}/Attributes`, { OnOff: on });
}
catch (error) {
this.logger.error(`Failed to set ${this.accessory.context.device.name} ${on ? "on" : "off"}`, axios_1.default.isAxiosError(error) ? (_a = error.response) === null || _a === void 0 ? void 0 : _a.data : error);
}
}
async getOn() {
this.logger.debug(`Getting ${this.accessory.context.device.name} onOff status`);
return this.device.state === "ON";
}
}
exports.Outlet = Outlet;
//# sourceMappingURL=Outlet.js.map