homebridge-loxone-proxy
Version:
Homebridge Dynamic Platform Plugin which exposes a Loxone System to Homekit.
54 lines • 2.31 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Switch = void 0;
const BaseService_1 = require("./BaseService");
class Switch extends BaseService_1.BaseService {
constructor() {
super(...arguments);
this.State = {
On: false,
};
}
setupService() {
const switchType = this.getSwitchType();
this.service = (this.secondaryService)
? this.accessory.getService(this.device.name) ||
this.accessory.addService(switchType, this.device.name, `${this.device.uuidAction}/${this.device.cat}`)
: this.accessory.getService(switchType) || this.accessory.addService(switchType);
if (this.secondaryService) {
this.service.setCharacteristic(this.platform.Characteristic.Name, this.device.name);
this.service.setCharacteristic(this.platform.Characteristic.ConfiguredName, this.device.name);
}
this.service.getCharacteristic(this.platform.Characteristic.On)
.onSet(this.setOn.bind(this))
.onGet(this.getOn.bind(this));
}
getSwitchType() {
return this.device.cat === 'lights'
? this.platform.Service.Lightbulb
: this.platform.Service.Switch;
}
updateService(message) {
this.platform.log.debug(`[${this.device.name}] Callback state update for Switch: ${!!message.value}`);
this.State.On = !!message.value;
this.service.getCharacteristic(this.platform.Characteristic.On).updateValue(this.State.On);
}
async setOn(value) {
var _a;
this.State.On = value;
this.platform.log.debug(`[${this.device.name}] Characteristic.On update from Homekit ->`, value);
if (this.handleLoxoneCommand && this.State.On) {
this.handleLoxoneCommand((_a = this.secondaryService) === null || _a === void 0 ? void 0 : _a.cat);
}
else {
const command = this.State.On ? 'On' : 'Off';
this.platform.log.debug(`[${this.device.name}] Send command to Loxone: ${command}`);
this.platform.LoxoneHandler.sendCommand(this.device.uuidAction, command);
}
}
async getOn() {
return this.State.On;
}
}
exports.Switch = Switch;
//# sourceMappingURL=Switch.js.map