@pietrolubini/homebridge-ecoflow
Version:
Homebridge plugin for EcoFlow devices
207 lines • 11.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GlacierAccessory = void 0;
const ecoFlowAccessoryWithQuotaBase_1 = require("@ecoflow/accessories/ecoFlowAccessoryWithQuotaBase");
const glacierHttpApiContracts_1 = require("@ecoflow/accessories/glacier/interfaces/glacierHttpApiContracts");
const glacierMqttApiContracts_1 = require("@ecoflow/accessories/glacier/interfaces/glacierMqttApiContracts");
const outletBatteryService_1 = require("@ecoflow/accessories/glacier/services/outletBatteryService");
const switchDetachIceService_1 = require("@ecoflow/accessories/glacier/services/switchDetachIceService");
const switchEcoModeService_1 = require("@ecoflow/accessories/glacier/services/switchEcoModeService");
const switchMakeIceService_1 = require("@ecoflow/accessories/glacier/services/switchMakeIceService");
const thermostatFridgeDualLeftZoneService_1 = require("@ecoflow/accessories/glacier/services/thermostatFridgeDualLeftZoneService");
const thermostatFridgeDualRightZoneService_1 = require("@ecoflow/accessories/glacier/services/thermostatFridgeDualRightZoneService");
const thermostatFridgeSingleZoneService_1 = require("@ecoflow/accessories/glacier/services/thermostatFridgeSingleZoneService");
const characteristicContracts_1 = require("@ecoflow/characteristics/characteristicContracts");
const batteryStatusService_1 = require("@ecoflow/services/batteryStatusService");
const contactSensorService_1 = require("@ecoflow/services/contactSensorService");
class GlacierAccessory extends ecoFlowAccessoryWithQuotaBase_1.EcoFlowAccessoryWithQuotaBase {
batteryStatusService;
fridgeDualLeftZoneService;
fridgeDualRightZoneService;
fridgeSingleZoneService;
switchEcoModeService;
contactSensorDoorService;
outletBatteryService;
switchMakeIceSmallService;
switchMakeIceLargeService;
switchDetachIceService;
constructor(platform, accessory, config, log, httpApiManager, mqttApiManager, batteryStatusProvider) {
super(platform, accessory, config, log, httpApiManager, mqttApiManager);
this.batteryStatusService = new batteryStatusService_1.BatteryStatusService(this, batteryStatusProvider);
this.fridgeDualLeftZoneService = new thermostatFridgeDualLeftZoneService_1.ThermostatFridgeDualLeftZoneService(this);
this.fridgeDualRightZoneService = new thermostatFridgeDualRightZoneService_1.ThermostatFridgeDualRightZoneService(this);
this.fridgeSingleZoneService = new thermostatFridgeSingleZoneService_1.ThermostatFridgeSingleZoneService(this);
this.switchEcoModeService = new switchEcoModeService_1.SwitchEcoModeService(this);
this.contactSensorDoorService = new contactSensorService_1.ContactSensorService(this, 'Door');
this.outletBatteryService = new outletBatteryService_1.OutletBatteryService(this, batteryStatusProvider);
this.switchMakeIceSmallService = new switchMakeIceService_1.SwitchMakeIceService(this, glacierMqttApiContracts_1.IceCubeShapeType.Small);
this.switchMakeIceLargeService = new switchMakeIceService_1.SwitchMakeIceService(this, glacierMqttApiContracts_1.IceCubeShapeType.Large);
this.switchDetachIceService = new switchDetachIceService_1.SwitchDetachIceService(this);
}
getServices() {
return [
this.batteryStatusService,
this.fridgeDualLeftZoneService,
this.fridgeDualRightZoneService,
this.fridgeSingleZoneService,
this.switchEcoModeService,
this.contactSensorDoorService,
this.outletBatteryService,
this.switchMakeIceSmallService,
this.switchMakeIceLargeService,
this.switchDetachIceService,
];
}
processQuotaMessage(message) {
const glacierMessage = message;
if (glacierMessage.typeCode === glacierMqttApiContracts_1.GlacierMqttMessageType.EMS) {
const emsStatus = message.params;
Object.assign(this.quota.bms_emsStatus, emsStatus);
this.updateEmsValues(emsStatus);
}
else if (glacierMessage.typeCode === glacierMqttApiContracts_1.GlacierMqttMessageType.BMS) {
const bmsStatus = message.params;
Object.assign(this.quota.bms_bmsStatus, bmsStatus);
this.updateBmsValues(bmsStatus);
}
else if (glacierMessage.typeCode === glacierMqttApiContracts_1.GlacierMqttMessageType.PD) {
const pdStatus = message.params;
Object.assign(this.quota.pd, pdStatus);
this.updatePdValues(pdStatus);
}
}
initializeQuota(quota) {
const result = quota ?? {};
if (!result.bms_emsStatus) {
result.bms_emsStatus = {};
}
if (!result.bms_bmsStatus) {
result.bms_bmsStatus = {};
}
if (!result.pd) {
result.pd = {};
}
return result;
}
updateInitialValues(initialData) {
this.updateEmsInitialValues(initialData.bms_emsStatus);
this.updateBmsInitialValues(initialData.bms_bmsStatus);
this.updatePdInitialValues(initialData.pd);
}
updateEmsInitialValues(params) {
const message = {
typeCode: glacierMqttApiContracts_1.GlacierMqttMessageType.EMS,
params,
};
this.processQuotaMessage(message);
}
updateBmsInitialValues(params) {
const message = {
typeCode: glacierMqttApiContracts_1.GlacierMqttMessageType.BMS,
params,
};
this.processQuotaMessage(message);
}
updatePdInitialValues(params) {
const message = {
typeCode: glacierMqttApiContracts_1.GlacierMqttMessageType.PD,
params,
};
this.processQuotaMessage(message);
}
updateEmsValues(params) {
if (params.lcdSoc !== undefined && params.minDsgSoc !== undefined) {
this.batteryStatusService.updateBatteryLevel(params.lcdSoc, params.minDsgSoc);
this.outletBatteryService.updateBatteryLevel(params.lcdSoc, params.minDsgSoc);
}
}
updateBmsValues(params) {
if (params.inWatts !== undefined) {
const isCharging = params.inWatts > 0 && (params.outWatts === undefined || params.inWatts !== params.outWatts);
this.batteryStatusService.updateChargingState(isCharging);
this.outletBatteryService.updateChargingState(isCharging);
this.outletBatteryService.updateInputConsumption(params.inWatts);
}
if (params.outWatts !== undefined) {
this.outletBatteryService.updateOutputConsumption(params.outWatts);
}
}
updatePdValues(params) {
this.updateFridgeZonesValues(params);
this.updateStateValues(params);
this.updateIceMakingValues(params);
}
updateFridgeZonesValues(params) {
if (params.pwrState !== undefined) {
const coolerState = params.pwrState === characteristicContracts_1.EnableType.On ? characteristicContracts_1.FridgeStateType.On : characteristicContracts_1.FridgeStateType.Off;
this.fridgeSingleZoneService.updateTargetState(coolerState);
this.fridgeDualLeftZoneService.updateTargetState(coolerState);
this.fridgeDualRightZoneService.updateTargetState(coolerState);
this.outletBatteryService.updateState(params.pwrState === characteristicContracts_1.EnableType.On);
}
if (params.flagTwoZone !== undefined && params.flagTwoZone === glacierHttpApiContracts_1.CoolingZoneType.Dual) {
this.fridgeSingleZoneService.updateEnabled(false);
this.fridgeDualLeftZoneService.updateEnabled(true);
this.fridgeDualRightZoneService.updateEnabled(true);
}
if (params.flagTwoZone !== undefined && params.flagTwoZone === glacierHttpApiContracts_1.CoolingZoneType.Single) {
this.fridgeSingleZoneService.updateEnabled(true);
this.fridgeDualLeftZoneService.updateEnabled(false);
this.fridgeDualRightZoneService.updateEnabled(false);
}
if (params.tmpL !== undefined) {
this.fridgeDualLeftZoneService.updateCurrentTemperature(params.tmpL);
}
if (params.tmpR !== undefined) {
this.fridgeDualRightZoneService.updateCurrentTemperature(params.tmpR);
}
if (params.tmpAver !== undefined) {
this.fridgeSingleZoneService.updateCurrentTemperature(params.tmpAver);
}
if (params.tmpLSet !== undefined) {
this.fridgeDualLeftZoneService.updateTargetTemperature(params.tmpLSet);
}
if (params.tmpRSet !== undefined) {
this.fridgeDualRightZoneService.updateTargetTemperature(params.tmpRSet);
}
if (params.tmpMSet !== undefined) {
this.fridgeSingleZoneService.updateTargetTemperature(params.tmpMSet);
}
}
updateStateValues(params) {
if (params.coolMode !== undefined) {
this.switchEcoModeService.updateState(params.coolMode === glacierHttpApiContracts_1.CoolModeType.Eco);
}
if (params.doorStat !== undefined) {
this.contactSensorDoorService.updateState(params.doorStat === glacierHttpApiContracts_1.ContactSensorType.Closed);
}
}
updateIceMakingValues(params) {
if (params.iceMkMode !== undefined) {
const iceSmallMaking = params.iceMkMode === glacierHttpApiContracts_1.MakeIceStatusType.SmallInPreparation ||
params.iceMkMode === glacierHttpApiContracts_1.MakeIceStatusType.SmallInProgress;
const iceLargeMaking = params.iceMkMode === glacierHttpApiContracts_1.MakeIceStatusType.LargeInPreparation ||
params.iceMkMode === glacierHttpApiContracts_1.MakeIceStatusType.LargeInProgress;
this.switchMakeIceSmallService.updateEnabled(iceSmallMaking);
this.switchMakeIceLargeService.updateEnabled(iceLargeMaking);
this.switchDetachIceService.updateEnabled(false);
this.switchMakeIceSmallService.updateState(iceSmallMaking);
this.switchMakeIceLargeService.updateState(iceLargeMaking);
this.switchDetachIceService.updateState(false);
}
if (params.icePercent !== undefined && params.icePercent === 100) {
this.switchMakeIceSmallService.updateEnabled(true);
this.switchMakeIceLargeService.updateEnabled(true);
}
if (params.fsmState !== undefined) {
this.switchMakeIceSmallService.updateEnabled(params.fsmState === glacierHttpApiContracts_1.DetachIceStatusType.Completed);
this.switchMakeIceLargeService.updateEnabled(params.fsmState === glacierHttpApiContracts_1.DetachIceStatusType.Completed);
this.switchDetachIceService.updateEnabled(true);
this.switchMakeIceSmallService.updateState(false);
this.switchMakeIceLargeService.updateState(false);
this.switchDetachIceService.updateState(params.fsmState === glacierHttpApiContracts_1.DetachIceStatusType.InProgress);
}
}
}
exports.GlacierAccessory = GlacierAccessory;
//# sourceMappingURL=glacierAccessory.js.map