homebridge-loxone-proxy
Version:
Homebridge Dynamic Platform Plugin which exposes a Loxone System to Homekit.
56 lines • 2.46 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Radio = void 0;
const LoxoneAccessory_1 = require("../../LoxoneAccessory");
const Outlet_1 = require("../../homekit/services/Outlet");
const Switch_1 = require("../../homekit/services/Switch");
const Switch_2 = require("./Switch");
class Radio extends LoxoneAccessory_1.LoxoneAccessory {
configureServices() {
this.ItemStates = {
[this.device.states.activeOutput]: {
service: 'PrimaryService',
state: 'activeOutput',
},
};
this.registerRadioSwitches();
}
registerRadioSwitches() {
this.device.details.outputs[0] = this.device.details.allOff;
const outputs = this.device.details.outputs;
for (const key in outputs) {
const rawName = outputs[key];
const uniqueName = this.platform.generateUniqueName(this.device.room, rawName, `${this.device.uuidAction}:radio:${key}`);
const radioItem = {
...this.device,
name: uniqueName,
type: 'Switch',
cat: key,
details: {},
subControls: {},
};
const serviceType = Switch_2.Switch.determineSwitchType(radioItem, this.platform.config);
this.platform.log.info(`[Radio: ${uniqueName}] resolved to service type: ${serviceType}`);
this.Service[uniqueName] =
serviceType === 'outlet'
? new Outlet_1.Outlet(this.platform, this.Accessory, radioItem, this.handleLoxoneCommand.bind(this))
: new Switch_1.Switch(this.platform, this.Accessory, radioItem, this.handleLoxoneCommand.bind(this));
}
}
callBackHandler(message) {
const active = Number(message.value);
for (const serviceName in this.Service) {
const service = this.Service[serviceName];
message.value = active === Number(service.device.cat) ? 1 : 0;
this.Service[serviceName].updateService(message);
}
}
handleLoxoneCommand(value) {
const numeric = Number(value);
const command = numeric === 0 ? 'reset' : value;
this.platform.log.debug(`[${this.device.name}] Send command: ${command}`);
this.platform.LoxoneHandler.sendCommand(this.device.uuidAction, command);
}
}
exports.Radio = Radio;
//# sourceMappingURL=Radio.js.map