UNPKG

homebridge-pse-energy

Version:

Homebridge plugin to display Puget Sound Energy data via Opower API

40 lines (39 loc) 1.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PSEEnergyPlatform = void 0; const accessory_1 = require("./accessory"); class PSEEnergyPlatform { constructor(log, config, api) { this.log = log; this.config = config; this.api = api; this.accessories = []; this.log.debug('Finished initializing platform:', this.config.platform); this.pollingInterval = this.config.pollingInterval || 43200; this.cookie = this.config.cookie || ''; this.electricityAgreementId = this.config.electricityAgreementId; this.gasAgreementId = this.config.gasAgreementId; this.api.on('didFinishLaunching', () => this.discoverDevices()); } configureAccessory(accessory) { this.accessories.push(accessory); } async discoverDevices() { const accessoriesToRegister = []; const types = ['electricity', 'gas', 'total']; for (const type of types) { const uuid = this.api.hap.uuid.generate(`pse-energy-${type}`); const displayName = `PSE ${type.charAt(0).toUpperCase() + type.slice(1)}`; const accessory = new this.api.platformAccessory(displayName, uuid); new accessory_1.PSEEnergyAccessory(this, accessory, { cookie: this.cookie, electricityAgreementId: this.electricityAgreementId, gasAgreementId: this.gasAgreementId, type, }); accessoriesToRegister.push(accessory); } this.api.registerPlatformAccessories('homebridge-pse-energy', 'PSEEnergyPlatform', accessoriesToRegister); } } exports.PSEEnergyPlatform = PSEEnergyPlatform;