UNPKG

homebridge-loxone-proxy

Version:

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

87 lines 4.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LoxoneAccessory = void 0; class LoxoneAccessory { constructor(platform, device) { this.platform = platform; this.device = device; this.Service = {}; this.ItemStates = {}; this.callBack = (message) => { if (message.uuid) { const itemState = this.ItemStates[message.uuid]; message.service = itemState.service; message.state = itemState.state; this.callBackHandler(message); } }; if (this.platform.AccessoryCount >= 149) { this.platform.log.info(`[${device.type}Item] Max HomeKit Accessories limit reached. Item not mapped: ${device.name}`); return; } if (!this.isSupported()) { this.platform.log.debug(`[${device.type}Item] Skipping unsupported item: ${device.name}`); return; } this.setupAccessory(); } isSupported() { return true; } setupAccessory() { const uuid = this.platform.api.hap.uuid.generate(this.device.uuidAction); this.Accessory = this.getOrCreateAccessory(uuid); this.Accessory.context.device = this.device; this.Accessory.context.mapped = true; this.configureServices(this.Accessory); this.setupListeners(); this.platform.mappedAccessories.add(this.Accessory.UUID); this.platform.AccessoryCount++; } getOrCreateAccessory(uuid) { var _a, _b; let accessory = this.platform.accessories.find((acc) => acc.UUID === uuid); const baseName = (_a = this.device.name) !== null && _a !== void 0 ? _a : 'Unnamed'; const roomName = (_b = this.device.room) !== null && _b !== void 0 ? _b : 'Unknown'; if (!accessory) { const uniqueName = this.platform.generateUniqueName(roomName, baseName, uuid); accessory = new this.platform.api.platformAccessory(uniqueName, uuid); this.platform.api.registerPlatformAccessories('homebridge-loxone-proxy', 'LoxonePlatform', [accessory]); this.platform.log.debug(`[${this.device.type}Item] Adding new accessory: ${uniqueName} (original: ${this.device.name})`); } else { this.platform.log.debug(`[${this.device.type}Item] Restoring accessory from cache: ${accessory.displayName} (original: ${this.device.name})`); } const accessoryInfoService = accessory.getService(this.platform.Service.AccessoryInformation); if (accessoryInfoService) { accessoryInfoService .setCharacteristic(this.platform.Characteristic.Manufacturer, 'Loxone') .setCharacteristic(this.platform.Characteristic.Model, this.device.room) .setCharacteristic(this.platform.Characteristic.SerialNumber, this.device.uuidAction) .setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); } return accessory; } configureServices(accessory) { } handleLoxoneCommand(value) { this.platform.log.info(`[${this.device.name}][handleLoxoneCommand] Function Not Implemented`); } setupListeners() { this.platform.log.debug(`[${this.device.name}] Registering Listeners for ${this.device.type}Item`); for (const state in this.ItemStates) { this.platform.LoxoneHandler.registerListenerForUUID(state, this.callBack.bind(this)); } } callBackHandler(message) { this.platform.log.debug(`[${this.device.name}] Callback service: ${message.service}`); const updateService = new Function('message', `return this.Service["${message.service}"].updateService(message);`); updateService.call(this, message); } matchAlias(deviceName, alias) { const aliasRegex = alias.trim().replace(/%/g, '.*').replace(/\s+/g, '\\s*'); return new RegExp(aliasRegex, 'i').test(deviceName.trim()); } } exports.LoxoneAccessory = LoxoneAccessory; //# sourceMappingURL=LoxoneAccessory.js.map