Skip to content

Commit

Permalink
Improve Eco Modes handling on 745 platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
mletenay committed Apr 12, 2024
1 parent 7846c88 commit 59971c6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
12 changes: 10 additions & 2 deletions goodwe/et.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down Expand Up @@ -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:
Expand All @@ -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')
Expand Down
29 changes: 29 additions & 0 deletions goodwe/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 59971c6

Please sign in to comment.