UNPKG

@pietrolubini/homebridge-ecoflow

Version:
120 lines 6.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeltaProAccessory = void 0; const outletAcService_1 = require("@ecoflow/accessories/batteries/deltapro/services/outletAcService"); const outletCarService_1 = require("@ecoflow/accessories/batteries/deltapro/services/outletCarService"); const outletUsbService_1 = require("@ecoflow/accessories/batteries/deltapro/services/outletUsbService"); const switchXboostService_1 = require("@ecoflow/accessories/batteries/deltapro/services/switchXboostService"); const batteryHttpApiContracts_1 = require("@ecoflow/accessories/batteries/interfaces/batteryHttpApiContracts"); const ecoFlowAccessoryWithQuotaBase_1 = require("@ecoflow/accessories/ecoFlowAccessoryWithQuotaBase"); const characteristicContracts_1 = require("@ecoflow/characteristics/characteristicContracts"); const batteryStatusService_1 = require("@ecoflow/services/batteryStatusService"); class DeltaProAccessory extends ecoFlowAccessoryWithQuotaBase_1.EcoFlowAccessoryWithQuotaBase { batteryStatusService; outletUsbService; outletAcService; outletCarService; switchXboostService; constructor(platform, accessory, config, log, httpApiManager, mqttApiManager, batteryStatusProvider) { super(platform, accessory, config, log, httpApiManager, mqttApiManager); this.batteryStatusService = new batteryStatusService_1.BatteryStatusService(this, batteryStatusProvider); this.outletUsbService = new outletUsbService_1.OutletUsbService(this, batteryStatusProvider); this.outletAcService = new outletAcService_1.OutletAcService(this, batteryStatusProvider); this.outletCarService = new outletCarService_1.OutletCarService(this, batteryStatusProvider); this.switchXboostService = new switchXboostService_1.SwitchXboostService(this); } getServices() { return [ this.batteryStatusService, this.outletUsbService, this.outletAcService, this.outletCarService, this.switchXboostService, ]; } processQuotaMessage(message) { const data = message.data; if (data?.ems !== undefined && Object.keys(data.ems).length > 0) { Object.assign(this.quota.ems, data.ems); this.updateEmsValues(data.ems); } if (data?.inv !== undefined && Object.keys(data.inv).length > 0) { Object.assign(this.quota.inv, data.inv); this.updateInvValues(data.inv); } if (data?.pd !== undefined && Object.keys(data.pd).length > 0) { Object.assign(this.quota.pd, data.pd); this.updatePdValues(data.pd); } } initializeQuota(quota) { const result = quota ?? {}; if (!result.ems) { result.ems = {}; } if (!result.inv) { result.inv = {}; } if (!result.pd) { result.pd = {}; } return result; } updateInitialValues(data) { const message = { data, }; this.processQuotaMessage(message); } updateEmsValues(params) { if (params.f32LcdShowSoc !== undefined && params.minDsgSoc !== undefined) { this.batteryStatusService.updateBatteryLevel(params.f32LcdShowSoc, params.minDsgSoc); this.outletAcService.updateBatteryLevel(params.f32LcdShowSoc, params.minDsgSoc); this.outletUsbService.updateBatteryLevel(params.f32LcdShowSoc, params.minDsgSoc); this.outletCarService.updateBatteryLevel(params.f32LcdShowSoc, params.minDsgSoc); } } updateInvValues(params) { if (params.inputWatts !== undefined) { const isCharging = params.inputWatts > 0 && (params.outputWatts === undefined || params.inputWatts !== params.outputWatts); this.batteryStatusService.updateChargingState(isCharging); this.outletAcService.updateChargingState(isCharging); this.outletUsbService.updateChargingState(isCharging); this.outletCarService.updateChargingState(isCharging); this.outletAcService.updateInputConsumption(params.inputWatts); this.outletUsbService.updateInputConsumption(params.inputWatts); this.outletCarService.updateInputConsumption(params.inputWatts); } if (params.outputWatts !== undefined) { this.outletAcService.updateOutputConsumption(params.outputWatts); } if (params.cfgAcEnabled !== undefined && params.cfgAcEnabled !== batteryHttpApiContracts_1.AcEnableType.Ignore) { this.outletAcService.updateState(params.cfgAcEnabled === batteryHttpApiContracts_1.AcEnableType.On); } if (params.cfgAcXboost !== undefined && params.cfgAcXboost !== batteryHttpApiContracts_1.AcXBoostType.Ignore) { this.switchXboostService.updateState(params.cfgAcXboost === batteryHttpApiContracts_1.AcXBoostType.On); } } updatePdValues(params) { if (params.carState !== undefined) { this.outletCarService.updateState(params.carState === characteristicContracts_1.EnableType.On); } if (params.carWatts !== undefined) { this.outletCarService.updateOutputConsumption(params.carWatts); } if (params.dcOutState !== undefined) { this.outletUsbService.updateState(params.dcOutState === characteristicContracts_1.EnableType.On); } if (params.usb1Watts !== undefined || params.usb2Watts !== undefined || params.qcUsb1Watts !== undefined || params.qcUsb2Watts !== undefined || params.typec1Watts !== undefined || params.typec2Watts !== undefined) { const usbWatts = this.sum(params.usb1Watts, params.usb2Watts, params.qcUsb1Watts, params.qcUsb2Watts, params.typec1Watts, params.typec2Watts); this.outletUsbService.updateOutputConsumption(usbWatts); } } } exports.DeltaProAccessory = DeltaProAccessory; //# sourceMappingURL=deltaProAccessory.js.map