UNPKG

homebridge-velux-kfx210

Version:

A Homebridge plugin integrating with a Velux KFX 210 control panel via RaspberryPi + Pimoroni Automation HAT.

46 lines 1.83 kB
import { KFX210Accessory } from './platformAccessory.js'; import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js'; export class KFX210Platform { log; config; api; Service; Characteristic; accessories = new Map(); constructor(log, config, api) { this.log = log; this.config = config; this.api = api; this.Service = api.hap.Service; this.Characteristic = api.hap.Characteristic; this.api.on('didFinishLaunching', () => { this.discoverDevices(); }); } configureAccessory(accessory) { this.log.info('Loading accessory from cache:', accessory.displayName); this.accessories.set(accessory.UUID, accessory); } discoverDevices() { const uuid = this.api.hap.uuid.generate('velux-kfx210'); const existingAccessory = this.accessories.get(uuid); if (existingAccessory) { this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName); new KFX210Accessory(this, existingAccessory); } else { this.log.info('Adding new accessory: Velux KFX210'); const accessory = new this.api.platformAccessory('Velux KFX210', uuid); new KFX210Accessory(this, accessory); this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]); } // Remove any stale cached accessories for (const [cachedUUID, cachedAccessory] of this.accessories) { if (cachedUUID !== uuid) { this.log.info('Removing stale accessory from cache:', cachedAccessory.displayName); this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [cachedAccessory]); } } } } //# sourceMappingURL=platform.js.map