UNPKG

homebridge-chuango-h4

Version:

A homebridge plugin for the Chuango H4 home security system.

58 lines 2.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChuangoH4HomebridgePlatform = void 0; const settings_1 = require("./settings"); const platformAccessory_1 = require("./platformAccessory"); const chuango_h4_client_1 = require("chuango-h4-client"); class ChuangoH4HomebridgePlatform { 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 is used to track restored cached accessories this.accessories = []; this.log.debug('Finished initializing platform Chuango H4'); this.api.on('didFinishLaunching', () => { this.log.info('Logging in...'); chuango_h4_client_1.Client.login(this.config.username, this.config.password, this.config.guid).then((client) => { this.log.info('Login successful'); this.discoverDevices(client); }).catch((e) => { this.log.error(e); }); }); } 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); } exploreDevice(client, device) { client.connect(device).then((connection) => { this.log.info('Connected to device ' + device.deviceID); const uuid = this.api.hap.uuid.generate(device.deviceID); const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid); if (existingAccessory) { new platformAccessory_1.ChuangoH4PlatformAccessory(this, existingAccessory, connection); } else { const accessory = new this.api.platformAccessory(device.deviceID, uuid); new platformAccessory_1.ChuangoH4PlatformAccessory(this, accessory, connection); this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [accessory]); } }); } discoverDevices(client) { this.log.info('Discovering chuango devices...'); client.listDevices().then((devices) => { for (const device of devices) { this.log.info('Found device ' + device.deviceID + ' connecting...'); this.exploreDevice(client, device); } }); } } exports.ChuangoH4HomebridgePlatform = ChuangoH4HomebridgePlatform; //# sourceMappingURL=platform.js.map