UNPKG

homebridge-homekit-proxy

Version:

Homebridge Homekit Proxy allows you to control HomeKit-enabled Devices directly from within HomeBridege. (Based on homebridge-homekit-controller by MartinPham)

53 lines 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HKPlatform = void 0; const HKClient_1 = require("./HKClient"); const settings_1 = require("./settings"); const SupportedDevices_1 = require("./SupportedDevices"); class HKPlatform { constructor(log, config, api) { this.config = config; this.api = api; this.log = log; this.supported = new SupportedDevices_1.SupportedServices(api); this.accessories = []; const self = this; this.clients = this.config.services === undefined ? [] : this.config.services.map((serviceConfig) => new HKClient_1.HKClient(serviceConfig, self)); this.api.on("didFinishLaunching" /* DID_FINISH_LAUNCHING */, () => { if (this.clients.length === 0) { this.clientFinishedLaunching(undefined); } }); } /** * REQUIRED - Homebridge will call the "configureAccessory" method once for every cached * accessory restored */ configureAccessory(inAccessory) { this.log.debug(`Loaded Accesory ${inAccessory.displayName} (${inAccessory.UUID})`); const accessory = inAccessory; accessory._wasUsed = false; this.accessories.push(accessory); } clientFinishedLaunching(cl) { const allReady = this.clients.map((c) => c.didFinishStartup).filter((ok) => !ok).length === 0; if (cl !== undefined) { this.log.info(`${cl.name} finished Startup. ${allReady ? 'All Clients ready now' : ''}`); } else if (allReady) { this.log.info('All Clients ready now'); } if (allReady) { this.log.info('Loaded Accesories'); this.log.info(this.accessories.map((a) => ` - [${a._wasUsed ? 'X' : ' '}] ${a.displayName} (${a.UUID})`).join('\n')); const unused = this.accessories.filter((a) => a._wasUsed === false); this.log.warn(`Found ${unused.length} unused accessories`); if (process.argv.some((v) => v === '-Q')) { this.log.warn(' --> Deleting all unused accessories'); unused.forEach((a) => this.api.unregisterPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [a])); } } } } exports.HKPlatform = HKPlatform; //# sourceMappingURL=HKPlatform.js.map