UNPKG

homebridge-loxone-proxy

Version:

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

48 lines 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Switch = void 0; const LoxoneAccessory_1 = require("../../LoxoneAccessory"); const LockMechanism_1 = require("../../homekit/services/LockMechanism"); const Outlet_1 = require("../../homekit/services/Outlet"); const Switch_1 = require("../../homekit/services/Switch"); class Switch extends LoxoneAccessory_1.LoxoneAccessory { configureServices() { var _a; this.ItemStates = { [this.device.states.active]: { service: 'PrimaryService', state: 'active', }, }; const serviceType = ((_a = this.device.details) === null || _a === void 0 ? void 0 : _a.serviceType) || Switch.determineSwitchType(this.device, this.platform.config); switch (serviceType) { case 'lock': this.Service.PrimaryService = new LockMechanism_1.LockMechanism(this.platform, this.Accessory); break; case 'outlet': this.Service.PrimaryService = new Outlet_1.Outlet(this.platform, this.Accessory); break; default: this.Service.PrimaryService = new Switch_1.Switch(this.platform, this.Accessory); break; } } static determineSwitchType(device, config) { var _a, _b; const name = (device.name || '').toLowerCase(); const icon1 = (device.catIcon || '').toLowerCase(); const icon2 = (device.defaultIcon || '').toLowerCase(); const matchesIcon = (icon) => icon1.includes(icon) || icon2.includes(icon); const matchesAlias = (alias) => !!alias && new RegExp(`\\b${alias.toLowerCase()}\\b`, 'i').test(name); if (matchesIcon('lock') || matchesAlias((_a = config.switchAlias) === null || _a === void 0 ? void 0 : _a.Lock)) { return 'lock'; } if (matchesIcon('outlet') || matchesAlias((_b = config.switchAlias) === null || _b === void 0 ? void 0 : _b.Outlet)) { return 'outlet'; } return 'switch'; } } exports.Switch = Switch; //# sourceMappingURL=Switch.js.map