UNPKG

homebridge-mhi-wfrac

Version:

A homebridge plugin for Mitshubishi WF-RAC aircos (using the Smart M-Air app)

60 lines 2.6 kB
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js'; import { WFRACAccessory } from './platformAccessory.js'; export class HomebridgeMHIWFRACPlatform { log; config; api; Service; Characteristic; // this is used to track restored cached accessories accessories = []; constructor(log, config, api) { this.log = log; this.config = config; this.api = api; this.Service = api.hap.Service; this.Characteristic = api.hap.Characteristic; this.log.info('Finished initializing platform:', 'Homebridge MHI WFRAC'); if (!log.success) { log.success = log.info; } this.api.on('didFinishLaunching', () => { log.debug('Executed didFinishLaunching callback'); // run the method to discover / register your devices as accessories this.configureDevices(); }); } 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); } configureDevices() { const deviceConfigs = this.config.devices; deviceConfigs.forEach((device) => { const uuid = this.api.hap.uuid.generate(device.mac); // Check if this accessory has already been registered const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid); if (existingAccessory) { // Accessory exists, restore from cache this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName); new WFRACAccessory(this, existingAccessory, device.ip); } else { // Accessory does not exist, create a new one this.log.info('Adding new accessory:', device.name); const accessory = new this.api.platformAccessory(device.name, uuid); // Store device details in accessory.context accessory.context.device = { name: device.name, uniqueId: uuid, }; // Create the accessory handler new WFRACAccessory(this, accessory, device.ip); // Register the accessory with Homebridge this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]); } }); } } //# sourceMappingURL=platform.js.map