UNPKG

@pietrolubini/homebridge-ecoflow

Version:
81 lines 3.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SmartPlugAccessory = void 0; const ecoFlowAccessoryWithQuotaBase_1 = require("@ecoflow/accessories/ecoFlowAccessoryWithQuotaBase"); const smartPlugMqttApiContracts_1 = require("@ecoflow/accessories/smartplug/interfaces/smartPlugMqttApiContracts"); const brightnessService_1 = require("@ecoflow/accessories/smartplug/services/brightnessService"); const outletService_1 = require("@ecoflow/accessories/smartplug/services/outletService"); const temperatureSensorService_1 = require("@ecoflow/services/temperatureSensorService"); class SmartPlugAccessory extends ecoFlowAccessoryWithQuotaBase_1.EcoFlowAccessoryWithQuotaBase { outletService; temperatureService; brightnessService; constructor(platform, accessory, config, log, httpApiManager, mqttApiManager) { super(platform, accessory, config, log, httpApiManager, mqttApiManager); this.outletService = new outletService_1.OutletService(this, config.outlet?.additionalCharacteristics); this.temperatureService = new temperatureSensorService_1.TemperatureSensorService(this); this.brightnessService = new brightnessService_1.BrightnessService(this, 1023); } getServices() { return [this.outletService, this.temperatureService, this.brightnessService]; } processQuotaMessage(message) { const smartPlugMessage = message; if (smartPlugMessage.cmdFunc === smartPlugMqttApiContracts_1.SmartPlugMqttMessageFuncType.Func2 && smartPlugMessage.cmdId === smartPlugMqttApiContracts_1.SmartPlugMqttMessageType.Heartbeat) { const heartbeat = message.param; Object.assign(this.quota['2_1'], heartbeat); this.updateHeartbeatValues(heartbeat); } } initializeQuota(quota) { const result = quota ?? {}; if (!result['2_1']) { result['2_1'] = {}; } return result; } updateInitialValues(initialData) { this.updateHeartbeatInitialValues(initialData['2_1']); } updateHeartbeatInitialValues(params) { const message = { cmdFunc: smartPlugMqttApiContracts_1.SmartPlugMqttMessageFuncType.Func2, cmdId: smartPlugMqttApiContracts_1.SmartPlugMqttMessageType.Heartbeat, param: params, }; this.processQuotaMessage(message); } updateHeartbeatValues(params) { this.updateOutletValues(params); this.updateBrightnessValues(params); this.updateTemperatureValues(params); } updateOutletValues(params) { if (params.switchSta !== undefined) { this.outletService.updateState(params.switchSta); } if (params.watts !== undefined) { this.outletService.updateOutputConsumption(params.watts * 0.1); } if (params.current !== undefined) { this.outletService.updateOutputCurrent(params.current * 0.001); } if (params.volt !== undefined) { this.outletService.updateOutputVoltage(params.volt); } } updateBrightnessValues(params) { if (params.brightness !== undefined) { this.brightnessService.updateState(params.brightness > 0); this.brightnessService.updateBrightness(params.brightness); } } updateTemperatureValues(params) { if (params.temp !== undefined) { this.temperatureService.updateCurrentTemperature(params.temp); } } } exports.SmartPlugAccessory = SmartPlugAccessory; //# sourceMappingURL=smartPlugAccessory.js.map