UNPKG

homebridge-obis-powermeter

Version:

Plugin for OBIS smart meter devices (SML/D0) to read power, energy, and voltages.

41 lines (40 loc) 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class PowerConsumption { constructor(_config, log, api, accessory, device) { this.log = log; this.api = api; this.accessory = accessory; this.device = device; this.Service = this.api.hap.Service; this.Characteristic = this.api.hap.Characteristic; // ensure HomeKit category is SENSOR (prevents light-bulb rendering in some clients) try { this.accessory.category = 10 /* this.api.hap.Categories.SENSOR */; } catch (_e) { /* noop: category not supported */ } if (!accessory) { log.error('No accessory provided'); return; } this.powerService = this.accessory.getService(this.Service.LightSensor) || this.accessory.addService(this.Service.LightSensor); const info = accessory.getService(this.Service.AccessoryInformation); if (!info) { log.error('No service accessory provided'); return; } info .setCharacteristic(this.Characteristic.Manufacturer, 'HomebridgeObis') .setCharacteristic(this.Characteristic.Model, device.product_name) .setCharacteristic(this.Characteristic.SerialNumber, `${device.serial}-power-consumption`); } beat(consumption) { let newPowerConsumptionLevel = 0.0001; if (consumption > 0) { newPowerConsumptionLevel = consumption; } this.powerService.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, newPowerConsumptionLevel); } } exports.default = PowerConsumption;