UNPKG

homebridge-pse-energy

Version:

Homebridge plugin to display Puget Sound Energy data via Opower API

35 lines (34 loc) 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PSEEnergyAccessory = void 0; const PSEClient_1 = require("./PSEClient"); class PSEEnergyAccessory { constructor(platform, accessory, options) { this.platform = platform; this.accessory = accessory; this.options = options; this.client = new PSEClient_1.PSEClient(options); const info = this.accessory.getService(this.platform.api.hap.Service.AccessoryInformation); info.setCharacteristic(this.platform.api.hap.Characteristic.Manufacturer, 'PSE') .setCharacteristic(this.platform.api.hap.Characteristic.Model, `PSE ${options.type}`); this.service = this.accessory.getService(this.platform.api.hap.Service.TemperatureSensor) || this.accessory.addService(this.platform.api.hap.Service.TemperatureSensor); this.service.setCharacteristic(this.platform.api.hap.Characteristic.Name, `${options.type} usage`); this.service.getCharacteristic(this.platform.api.hap.Characteristic.CurrentTemperature) .onGet(this.getValue.bind(this)); } async getValue() { const data = await this.client.fetchUsageData(); switch (this.options.type) { case 'electricity': return data.electricityUsage ?? 0; case 'gas': return data.gasUsage ?? 0; case 'total': return data.totalBill ?? 0; default: return 0; } } } exports.PSEEnergyAccessory = PSEEnergyAccessory;