UNPKG

homebridge-loxone-proxy

Version:

Homebridge Dynamic Platform Plugin which exposes a Loxone System to Homekit.

95 lines 4.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LightControllerV2 = void 0; const LoxoneAccessory_1 = require("../../LoxoneAccessory"); const Outlet_1 = require("../../homekit/services/Outlet"); const Switch_1 = require("../../homekit/services/Switch"); const ColorPickerV2_1 = require("./ColorPickerV2"); const Dimmer_1 = require("./Dimmer"); const Switch_2 = require("./Switch"); const typeClassMap = { 'ColorPickerV2': ColorPickerV2_1.ColorPickerV2, 'Dimmer': Dimmer_1.Dimmer, 'EIBDimmer': Dimmer_1.Dimmer, 'Switch': Switch_2.Switch, }; class LightControllerV2 extends LoxoneAccessory_1.LoxoneAccessory { isSupported() { this.registerChildItems(); return this.platform.config.options.MoodSwitches === 'enabled'; } configureServices() { this.device.name = this.platform.generateUniqueName(this.device.room, 'Moods', this.device.uuidAction); this.ItemStates = { [this.device.states.activeMoods]: { service: 'PrimaryService', state: 'activeMoods', }, }; this.platform.LoxoneHandler.pushCachedState(this, this.device.states.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 moodItem = { ...this.device, name: mood.name, cat: mood.id, details: {}, subControls: {}, }; const serviceType = Switch_2.Switch.determineSwitchType(moodItem, this.platform.config); this.Service[mood.name] = serviceType === 'outlet' ? new Outlet_1.Outlet(this.platform, this.Accessory, moodItem, this.handleLoxoneCommand.bind(this)) : new Switch_1.Switch(this.platform, this.Accessory, moodItem, this.handleLoxoneCommand.bind(this)); }); } registerChildItems() { var _a, _b, _c; if (!this.device.subControls || Object.keys(this.device.subControls).length === 0) { this.platform.log.debug(`[${this.device.name}] has no subControls – skipping`); return; } for (const childUuid in this.device.subControls) { const lightItem = this.device.subControls[childUuid]; if (!lightItem) { continue; } lightItem.details = lightItem.details || {}; if (((_a = lightItem.uuidAction) === null || _a === void 0 ? void 0 : _a.includes('/masterValue')) || ((_b = lightItem.uuidAction) === null || _b === void 0 ? void 0 : _b.includes('/masterColor'))) { continue; } lightItem.room = this.device.room; lightItem.cat = this.device.cat; lightItem.name = this.platform.generateUniqueName(lightItem.room, (_c = lightItem.name) !== null && _c !== void 0 ? _c : lightItem.type); const ControlClass = typeClassMap[lightItem.type]; if (!ControlClass) { this.platform.log.debug(`[${this.device.name}] Unsupported subcontrol type: ${lightItem.type}`); continue; } if (lightItem.type === 'Switch') { lightItem.details.serviceType = Switch_2.Switch.determineSwitchType(lightItem, this.platform.config); } new ControlClass(this.platform, lightItem); } } callBackHandler(message) { const currentID = parseInt(String(message.value).replace(/[[\]']+/g, ''), 10); for (const serviceName in this.Service) { const service = this.Service[serviceName]; message.value = currentID === parseInt(service.device.cat, 10) ? 1 : 0; service.updateService(message); } } handleLoxoneCommand(value) { const command = `changeTo/${value}`; this.platform.LoxoneHandler.sendCommand(this.device.uuidAction, command); } } exports.LightControllerV2 = LightControllerV2; //# sourceMappingURL=LightControllerV2.js.map