UNPKG

homebridge-loxone-proxy

Version:

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

127 lines 6.03 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LoxonePlatform = void 0; const LoxoneHandler_1 = __importDefault(require("./loxone/LoxoneHandler")); class LoxonePlatform { constructor(log, config, api) { this.log = log; this.config = config; this.api = api; this.AccessoryCount = 1; this.msInfo = {}; this.LoxoneItems = {}; this.Service = this.api.hap.Service; this.Characteristic = this.api.hap.Characteristic; this.accessories = []; this.api.on('didFinishLaunching', async () => { await this.LoxoneInit(); }); } async LoxoneInit() { this.LoxoneHandler = new LoxoneHandler_1.default(this); await this.waitForLoxoneConfig(); this.log.debug(`[LoxoneInit] Got Structure File; Last modified on ${this.LoxoneHandler.loxdata.lastModified}`); this.parseLoxoneConfig(this.LoxoneHandler.loxdata); } waitForLoxoneConfig() { return new Promise((resolve) => { const waitInterval = setInterval(() => { if (this.LoxoneHandler.loxdata) { clearInterval(waitInterval); resolve(); } }, 1000); }); } parseLoxoneConfig(config) { var _a, _b, _c; this.msInfo = config.msInfo; const LoxoneRooms = { ...config.rooms }; const LoxoneCats = { ...config.cats }; this.LoxoneItems = { ...config.controls }; for (const uuid in this.LoxoneItems) { const Item = this.LoxoneItems[uuid]; Item.room = ((_a = LoxoneRooms[Item.room]) === null || _a === void 0 ? void 0 : _a.name) || 'undefined'; Item.catIcon = ((_b = LoxoneCats[Item.cat]) === null || _b === void 0 ? void 0 : _b.image) || 'undefined'; Item.cat = ((_c = LoxoneCats[Item.cat]) === null || _c === void 0 ? void 0 : _c.type) || 'undefined'; } this.mapLoxoneItems(Object.values(this.LoxoneItems)); this.removeUnmappedAccessories(); } async mapLoxoneItems(items) { var _a; var _b, _c, _d, _e, _f, _g; const itemCache = {}; const ExcludedItemTypes = (_c = (_b = this.config.Exclusions) === null || _b === void 0 ? void 0 : _b.split(',')) !== null && _c !== void 0 ? _c : []; const RoomFilterList = (_f = (_e = (_d = this.config.roomfilter) === null || _d === void 0 ? void 0 : _d.list) === null || _e === void 0 ? void 0 : _e.split(',')) !== null && _f !== void 0 ? _f : []; const RoomFilterType = ((_g = this.config.roomfilter) === null || _g === void 0 ? void 0 : _g.type) || 'exclusion'; for (const item of items) { try { const itemType = item.type; const isRoomExluded = (RoomFilterType.toLowerCase() === 'exclusion' && RoomFilterList.includes(item.room.toLowerCase())) || (RoomFilterType.toLowerCase() === 'inclusion' && !RoomFilterList.includes(item.room.toLowerCase())); if (isRoomExluded) { this.log.debug(`[mapLoxoneItem][RoomExlusion] Skipping Excluded Room: ${item.name} in room ${item.room}`); } else if (ExcludedItemTypes.includes(itemType)) { this.log.debug(`[mapLoxoneItem][ItemTypeExlusion] Skipping Excluded ItemType: ${item.name} with type ${item.type}`); } else { if (!itemCache[itemType]) { const itemFile = await (_a = `./loxone/items/${itemType}`, Promise.resolve().then(() => __importStar(require(_a)))); itemCache[itemType] = itemFile; } const itemFile = itemCache[itemType]; const constructorName = Object.keys(itemFile)[0]; new itemFile[constructorName](this, item); } } catch (error) { this.log.debug(`[mapLoxoneItem] Skipping Unsupported ItemType: ${item.name} with type ${item.type}`); } } } removeUnmappedAccessories() { setTimeout(() => { this.accessories.forEach((accessory) => { if (!accessory.context.mapped) { this.log.debug('Remove accessory: ', accessory.displayName); this.api.unregisterPlatformAccessories('homebridge-loxone-proxy', 'LoxonePlatform', [accessory]); } }); }, 5000); } configureAccessory(accessory) { this.log.debug('Loading accessory from cache:', accessory.displayName); accessory.context.mapped = false; this.accessories.push(accessory); } } exports.LoxonePlatform = LoxonePlatform; //# sourceMappingURL=LoxonePlatform.js.map