Skip to content

Commit

Permalink
Add get_power() and get_power_unit() to EcoMode sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
mletenay committed May 6, 2024
1 parent ea30e80 commit 1449f9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
26 changes: 25 additions & 1 deletion goodwe/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,14 @@ def get_schedule_type(self) -> ScheduleType:
def set_schedule_type(self, schedule_type: ScheduleType, is745: bool):
"""Set the schedule type"""

@abstractmethod
def get_power(self) -> int:
"""Answer the power value"""

@abstractmethod
def get_power_unit(self) -> str:
"""Answer the power unit"""


class EcoModeV1(Sensor, EcoMode):
"""Sensor representing Eco Mode Battery Power Group encoded in 8 bytes"""
Expand Down Expand Up @@ -606,6 +614,14 @@ def set_schedule_type(self, schedule_type: ScheduleType, is745: bool):
"""Set the schedule type"""
pass

def get_power(self) -> int:
"""Answer the power value"""
return self.power

def get_power_unit(self) -> str:
"""Answer the power unit"""
return "%"

def as_eco_mode_v2(self) -> EcoModeV2:
"""Convert V1 to V2 EcoMode"""
result = EcoModeV2(self.id_, self.offset, self.name)
Expand Down Expand Up @@ -642,7 +658,7 @@ def __init__(self, id_: str, offset: int, name: str, schedule_type: ScheduleType
def __str__(self):
return f"{self.start_h}:{self.start_m}-{self.end_h}:{self.end_m} {self.days} " \
f"{self.months + ' ' if self.months else ''}" \
f"{self.schedule_type.decode_power(self.power)}{self.schedule_type.power_unit()} (SoC {self.soc}%) " \
f"{self.get_power()}{self.get_power_unit()} (SoC {self.soc}%) " \
f"{'On' if -10 < self.on_off < 0 else 'Off' if 10 > self.on_off >= 0 else 'Unset'}"

def read_value(self, data: ProtocolResponse):
Expand Down Expand Up @@ -736,6 +752,14 @@ def set_schedule_type(self, schedule_type: ScheduleType, is745: bool):
else:
self.schedule_type = schedule_type

def get_power(self) -> int:
"""Answer the power value"""
return self.schedule_type.decode_power(self.power)

def get_power_unit(self) -> str:
"""Answer the power unit"""
return self.schedule_type.power_unit()

def as_eco_mode_v1(self) -> EcoModeV1:
"""Convert V2 to V1 EcoMode"""
result = EcoModeV1(self.id_, self.offset, self.name)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ def test_eco_mode_v745(self):
self.assertFalse(testee.read(data).is_eco_charge_mode())
self.assertFalse(testee.read(data).is_eco_discharge_mode())
self.assertEqual(ScheduleType.ECO_MODE_745, testee.schedule_type)
self.assertEqual(1000, testee.power)
self.assertEqual(100, testee.get_power())
self.assertEqual("%", testee.get_power_unit())

data = MockResponse("10001600f97f00c800000fff")
self.assertEqual("16:0-22:0 Sun,Mon,Tue,Wed,Thu,Fri,Sat 20% (SoC 0%) On", testee.read(data).__str__())
Expand Down

0 comments on commit 1449f9a

Please sign in to comment.