Skip to content

Commit 4da578b

Browse files
authored
Extract and expose error code from StateResponse (#238)
1 parent b1ab71c commit 4da578b

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

msmart/device/AC/command.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ def __init__(self, payload: memoryview) -> None:
877877
self.target_humidity = None
878878
self.aux_heat = None
879879
self.independent_aux_heat = None
880+
self.error_code = None
880881

881882
self._parse(payload)
882883

@@ -974,6 +975,8 @@ def _parse(self, payload: memoryview) -> None:
974975

975976
self.display_on = (payload[14] != 0x70)
976977

978+
self.error_code = payload[16]
979+
977980
if len(payload) < 20:
978981
return
979982

msmart/device/AC/device.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ def __init__(self, ip: str, device_id: int, port: int, **kwargs) -> None:
197197
self._aux_mode = AirConditioner.AuxHeatMode.OFF
198198
self._supported_aux_modes = [AirConditioner.AuxHeatMode.OFF]
199199

200+
self._error_code = None
201+
200202
def _update_state(self, res: Response) -> None:
201203
"""Update the local state from a device state response."""
202204

@@ -251,6 +253,8 @@ def _update_state(self, res: Response) -> None:
251253
else:
252254
self._aux_mode = AirConditioner.AuxHeatMode.OFF
253255

256+
self._error_code = res.error_code
257+
254258
elif isinstance(res, PropertiesResponse):
255259
_LOGGER.debug(
256260
"Properties response payload from device %s: %s", self.id, res)
@@ -1025,6 +1029,10 @@ def aux_mode(self) -> AuxHeatMode:
10251029
def aux_mode(self, mode: AuxHeatMode) -> None:
10261030
self._aux_mode = mode
10271031

1032+
@property
1033+
def error_code(self) -> Optional[int]:
1034+
return self._error_code
1035+
10281036
def to_dict(self) -> dict:
10291037
return {**super().to_dict(), **{
10301038
"power": self.power_state,
@@ -1055,6 +1063,7 @@ def to_dict(self) -> dict:
10551063
"real_time_power_usage": self.get_real_time_power_usage(),
10561064
"rate_select": self.rate_select,
10571065
"aux_mode": self.aux_mode,
1066+
"error_code": self.error_code,
10581067
}}
10591068

10601069
# Deprecated methods and properties

msmart/device/AC/test_command.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class TestStateResponse(_TestResponseBase):
8686
"target_humidity",
8787
"aux_heat",
8888
"independent_aux_heat",
89+
"error_code",
8990
]
9091

9192
def _test_response(self, msg) -> StateResponse:

0 commit comments

Comments
 (0)