homebridge-homewizard-power-consumption
Version:
See current power consumption and power return in Homekit
28 lines (27 loc) • 1.24 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class PowerReturn {
constructor(config, log, api, accessory, device) {
this.config = config;
this.log = log;
this.api = api;
this.accessory = accessory;
this.device = device;
this.Service = this.api.hap.Service;
this.Characteristic = this.api.hap.Characteristic;
this.accessory.getService(this.Service.AccessoryInformation)
.setCharacteristic(this.Characteristic.Manufacturer, 'Homewizard')
.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) {
const minimumLuxLevel = 0.0001;
let newPowerConsumptionLevel = minimumLuxLevel;
if (consumption < 0) {
newPowerConsumptionLevel = consumption * -1;
}
this.powerService.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, newPowerConsumptionLevel);
}
}
exports.default = PowerReturn;