From 59971c68685326b14613369e6f586f45a86a0b25 Mon Sep 17 00:00:00 2001 From: mle Date: Fri, 12 Apr 2024 23:49:00 +0200 Subject: [PATCH] Improve Eco Modes handling on 745 platforms --- goodwe/et.py | 12 ++++++++++-- goodwe/sensor.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/goodwe/et.py b/goodwe/et.py index 6b5c05c..ff0b6d0 100644 --- a/goodwe/et.py +++ b/goodwe/et.py @@ -7,7 +7,7 @@ from .inverter import Inverter from .inverter import OperationMode from .inverter import SensorKind as Kind -from .model import is_2_battery, is_4_mppt, is_single_phase +from .model import is_2_battery, is_4_mppt, is_745_platform, is_single_phase from .protocol import ProtocolCommand, ModbusReadCommand, ModbusWriteCommand, ModbusWriteMultiCommand from .sensor import * @@ -645,8 +645,14 @@ async def set_operation_mode(self, operation_mode: OperationMode, eco_mode_power raise ValueError() if eco_mode_soc < 0 or eco_mode_soc > 100: raise ValueError() + eco_mode: EcoMode | Sensor = self._settings.get('eco_mode_1') - await self._read_setting(eco_mode) + # Load the current values to try to detect schedule type + try: + await self._read_setting(eco_mode) + except ValueError: + pass + eco_mode.set_schedule_type(ScheduleType.ECO_MODE, is_745_platform(self)) if operation_mode == OperationMode.ECO_CHARGE: await self.write_setting('eco_mode_1', eco_mode.encode_charge(eco_mode_power, eco_mode_soc)) else: @@ -656,6 +662,8 @@ async def set_operation_mode(self, operation_mode: OperationMode, eco_mode_power await self.write_setting('eco_mode_4_switch', 0) await self.write_setting('work_mode', 3) await self._set_offline(False) + if is_745_platform(self): + await self.write_setting('eco_mode_enable', 1) async def get_ongrid_battery_dod(self) -> int: return 100 - await self.read_setting('battery_discharge_depth') diff --git a/goodwe/sensor.py b/goodwe/sensor.py index 8dea878..0f2814f 100644 --- a/goodwe/sensor.py +++ b/goodwe/sensor.py @@ -480,6 +480,14 @@ def is_eco_charge_mode(self) -> bool: def is_eco_discharge_mode(self) -> bool: """Answer if it represents the emulated 24/7 fulltime discharge mode""" + @abstractmethod + def get_schedule_type(self) -> ScheduleType: + """Answer the schedule type""" + + @abstractmethod + def set_schedule_type(self, schedule_type: ScheduleType, is745: bool): + """Set the schedule type""" + class EcoModeV1(Sensor, EcoMode): """Sensor representing Eco Mode Battery Power Group encoded in 8 bytes""" @@ -563,6 +571,14 @@ def is_eco_discharge_mode(self) -> bool: and self.day_bits == 127 \ and self.power > 0 + def get_schedule_type(self) -> ScheduleType: + """Answer the schedule type""" + return ScheduleType.ECO_MODE + + def set_schedule_type(self, schedule_type: ScheduleType, is745: bool): + """Set the schedule type""" + pass + def as_eco_mode_v2(self) -> EcoModeV2: """Convert V1 to V2 EcoMode""" result = EcoModeV2(self.id_, self.offset, self.name) @@ -680,6 +696,19 @@ def is_eco_discharge_mode(self) -> bool: and self.power > 0 \ and (self.month_bits == 0 or self.month_bits == 0x0fff) + def get_schedule_type(self) -> ScheduleType: + """Answer the schedule type""" + return self.schedule_type + + def set_schedule_type(self, schedule_type: ScheduleType, is745: bool): + """Set the schedule type""" + if schedule_type == ScheduleType.ECO_MODE: + # try to keep-reuse the type, use is745 only when necessary + if self.schedule_type not in (ScheduleType.ECO_MODE, ScheduleType.ECO_MODE_745): + self.schedule_type = ScheduleType.ECO_MODE_745 if is745 else ScheduleType.ECO_MODE + else: + self.schedule_type = schedule_type + def as_eco_mode_v1(self) -> EcoModeV1: """Convert V2 to V1 EcoMode""" result = EcoModeV1(self.id_, self.offset, self.name)