homebridge-loxone-proxy
Version:
Homebridge Dynamic Platform Plugin which exposes a Loxone System to Homekit.
72 lines • 3.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LightControllerV2 = void 0;
const LoxoneAccessory_1 = require("../../LoxoneAccessory");
const Outlet_1 = require("../../homekit/services/Outlet");
const ColorPickerV2_1 = require("./ColorPickerV2");
const Dimmer_1 = require("./Dimmer");
const Switch_1 = require("./Switch");
const typeClassMap = {
'ColorPickerV2': ColorPickerV2_1.ColorPickerV2,
'Dimmer': Dimmer_1.Dimmer,
'EIBDimmer': Dimmer_1.Dimmer,
'Switch': Switch_1.Switch,
};
class LightControllerV2 extends LoxoneAccessory_1.LoxoneAccessory {
isSupported() {
this.registerChildItems();
this.device.name = `${this.device.room} Moods`;
return (this.platform.config.options.MoodSwitches === 'enabled') ? true : false;
}
configureServices() {
this.ItemStates = {
[this.device.states.activeMoods]: { 'service': 'PrimaryService', 'state': 'activeMoods' },
};
this.registerMoodSwitches();
}
registerMoodSwitches() {
const moods = JSON.parse(this.platform.LoxoneHandler.getLastCachedValue(this.device.states.moodList));
moods.filter(mood => mood.id !== 778).forEach(mood => {
const moodSwitchItem = {
...this.device,
name: `${mood.name}`,
cat: mood.id,
details: {},
subControls: {},
};
this.Service[mood.name] = new Outlet_1.Outlet(this.platform, this.Accessory, moodSwitchItem, this.handleLoxoneCommand.bind(this));
});
}
registerChildItems() {
for (const childUuid in this.device.subControls) {
const lightItem = this.device.subControls[childUuid];
if (lightItem.uuidAction.includes('/masterValue') || lightItem.uuidAction.includes('/masterColor')) {
continue;
}
lightItem.room = this.device.room;
lightItem.cat = this.device.cat;
const ControlClass = typeClassMap[lightItem.type];
if (ControlClass) {
new ControlClass(this.platform, lightItem);
}
}
}
callBackHandler(message) {
const currentIDpreg = message.value;
const currentID = parseInt(currentIDpreg.replace(/[[\]']+/g, ''));
for (const serviceName in this.Service) {
const service = this.Service[serviceName];
message.value = currentID === parseInt(service.device.cat) ? 1 : 0;
const updateService = new Function('message', `return this.Service["${serviceName}"].updateService(message);`);
updateService.call(this, message);
}
}
handleLoxoneCommand(value) {
this.platform.log.debug(`[${this.device.name}] MoodSwitch update from Homekit ->`, value);
const command = `changeTo/${value}`;
this.platform.log.debug(`[${this.device.name}] Send command to Loxone: ${command}`);
this.platform.LoxoneHandler.sendCommand(this.device.uuidAction, command);
}
}
exports.LightControllerV2 = LightControllerV2;
//# sourceMappingURL=LightControllerV2.js.map