UNPKG

homebridge-hsp

Version:

A plugin to control your HSP pellet stove with homebridge.

63 lines 2.88 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HspPlatform = void 0; const settings_1 = require("./settings"); const platformAccessory_1 = __importDefault(require("./platformAccessory")); class HspPlatform { constructor(log, config, api) { this.log = log; this.config = config; this.api = api; this.Service = this.api.hap.Service; this.Characteristic = this.api.hap.Characteristic; this.accessories = []; this.log = log; this.config = config; this.log.debug('Finished initializing platform:', this.config.name); this.api.on('didFinishLaunching', () => { log.debug('Executed didFinishLaunching callback'); /*this.accessories.forEach(function(accessory){ api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]); });*/ // run the method to discover / register your devices as accessories this.discoverDevices(); }); } configureAccessory(accessory) { this.log.info('Loading accessory from cache:', accessory.displayName); // add the restored accessory to the accessories cache so we can track if it has already been registered this.accessories.push(accessory); } discoverDevices() { const devices = [ { uniqueId: this.api.hap.uuid.generate('HSP-01'), displayName: 'HSP Pellet Ofen', }, ]; for (const device of devices) { const uuid = this.api.hap.uuid.generate(device.uniqueId); const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid); if (existingAccessory) { this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName); new platformAccessory_1.default(this, existingAccessory); } else { this.log.info('Adding new accessory:', device.displayName); const accessory = new this.api.platformAccessory(device.displayName, uuid); accessory.context.device = device; new platformAccessory_1.default(this, accessory); //this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]); this.api.publishExternalAccessories(settings_1.PLUGIN_NAME, [accessory]); } } for (const cachedAccessory of this.accessories) { this.api.unregisterPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [cachedAccessory]); } } } exports.HspPlatform = HspPlatform; //# sourceMappingURL=platform.js.map