UNPKG

homebridge-loxone-proxy

Version:

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

81 lines 3.59 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`); return; } if (!this.isSupported()) { this.platform.log.debug(`[${device.type}Item] Skipping unsupported item: ${this.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.AccessoryCount++; } getOrCreateAccessory(uuid) { let accessory = this.platform.accessories.find((acc) => acc.UUID === uuid); if (!accessory) { accessory = new this.platform.api.platformAccessory(this.device.name, uuid); this.platform.api.registerPlatformAccessories('homebridge-loxone-proxy', 'LoxonePlatform', [accessory]); this.platform.log.debug(`[${this.device.type}Item] Adding new accessory:`, this.device.name); } else { this.platform.log.debug(`[${this.device.type}Item] Restoring accessory from cache:`, accessory.displayName); } 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, this.device.name); } 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) { 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