homebridge-lg-ac
Version:
A Homebridge plugin for controlling/monitoring LG AirConditioning device via LG ThinQ platform.
60 lines • 2.4 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.ButtonUnit = void 0;
const events_1 = __importDefault(require("events"));
class ButtonUnit extends events_1.default {
constructor(controller, platform, accessory, buttonType) {
super();
this.controller = controller;
this.platform = platform;
this.accessory = accessory;
this.buttonType = buttonType;
const { Service: { Switch }, Characteristic, } = this.platform;
this.ThinQ = this.platform.ThinQ;
this.device = this.accessory.context.device;
this.service = this.accessory.getService(this.buttonName) ||
this.accessory.addService(Switch, this.buttonName, this.buttonName);
this.service.updateCharacteristic(Characteristic.ConfiguredName, this.buttonName);
this.service
.getCharacteristic(Characteristic.On)
.onSet((value) => {
this.toggle(value);
});
}
get buttonName() {
switch (this.buttonType) {
case 1 /* ButtonType.COMFORT_SLEEP */: return 'Comfort Sleep';
case 0 /* ButtonType.JET_MODE */: return 'Jet Mode';
case 2 /* ButtonType.LED */: return 'LED';
}
}
get currentState() {
switch (this.buttonType) {
case 1 /* ButtonType.COMFORT_SLEEP */: return this.controller.comfortMode;
case 0 /* ButtonType.JET_MODE */: return this.controller.jetMode;
case 2 /* ButtonType.LED */: return this.controller.isLightOn;
}
}
toggle(isOn) {
switch (this.buttonType) {
case 1 /* ButtonType.COMFORT_SLEEP */:
return this.controller.setComfortSleep(isOn);
case 0 /* ButtonType.JET_MODE */:
return this.controller.setJetMode(isOn);
case 2 /* ButtonType.LED */:
return this.controller.setLight(isOn);
}
}
update(device) {
const { Characteristic } = this.platform;
this.service.updateCharacteristic(Characteristic.On, this.currentState);
}
remove() {
this.accessory.removeService(this.service);
}
}
exports.ButtonUnit = ButtonUnit;
//# sourceMappingURL=ButtonUnit.js.map