UNPKG

homebridge-obis-powermeter

Version:

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

40 lines (39 loc) 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class PowerReturn { 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 } const info = this.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-return`); this.powerService = this.accessory.getService(this.Service.LightSensor) || this.accessory.addService(this.Service.LightSensor); } beat(consumption) { let newPowerConsumptionLevel = 0.0001; if (consumption < 0) { newPowerConsumptionLevel = consumption * -1; } this.powerService.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, newPowerConsumptionLevel); } } exports.default = PowerReturn;