Skip to content

Commit

Permalink
Fix condition in _update_state which caused zero values property valu…
Browse files Browse the repository at this point in the history
…es to not update the device state.

Update testcases to ensure this is tested
  • Loading branch information
mill1000 committed May 12, 2024
1 parent a4dfe52 commit 591783f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions msmart/device/AC/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ def _update_state(self, res: Union[StateResponse, PropertiesResponse]) -> None:

elif isinstance(res, PropertiesResponse):

if angle := res.get_property(PropertyId.SWING_LR_ANGLE):
if (angle := res.get_property(PropertyId.SWING_LR_ANGLE)) is not None:
self._horizontal_swing_angle = cast(
AirConditioner.SwingAngle,
AirConditioner.SwingAngle.get_from_value(angle))

if angle := res.get_property(PropertyId.SWING_UD_ANGLE):
if (angle := res.get_property(PropertyId.SWING_UD_ANGLE)) is not None:
self._vertical_swing_angle = cast(
AirConditioner.SwingAngle,
AirConditioner.SwingAngle.get_from_value(angle))
Expand Down
23 changes: 18 additions & 5 deletions msmart/device/AC/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,23 @@ def test_properties_response(self) -> None:
TEST_RESPONSE = bytes.fromhex(
"aa21ac00000000000303b10409000001000a00000100150000012b1e020000005fa3")

# Create a dummy device
device = AC(0, 0, 0)

# Set some properties
device.horizontal_swing_angle = AC.SwingAngle.POS_5
device.vertical_swing_angle = AC.SwingAngle.POS_5

resp = Response.construct(TEST_RESPONSE)
self.assertIsNotNone(resp)

# Assert response is a state response
self.assertEqual(type(resp), PropertiesResponse)

# Create a dummy device and process the response
device = AC(0, 0, 0)
# Process the response
device._process_state_response(resp)

# Assert state is expected
# TODO Test cases doesn't test values that differ from defaults
self.assertEqual(device.horizontal_swing_angle, AC.SwingAngle.OFF)
self.assertEqual(device.vertical_swing_angle, AC.SwingAngle.OFF)

Expand All @@ -161,14 +166,20 @@ def test_properties_ack_response(self) -> None:
TEST_RESPONSE = bytes.fromhex(
"aa18ac00000000000302b0020a0000013209001101000089a4")

# Create a dummy device
device = AC(0, 0, 0)

# Set some properties
device.horizontal_swing_angle = AC.SwingAngle.OFF
device.vertical_swing_angle = AC.SwingAngle.OFF

resp = Response.construct(TEST_RESPONSE)
self.assertIsNotNone(resp)

# Assert response is a state response
self.assertEqual(type(resp), PropertiesResponse)

# Create a dummy device and process the response
device = AC(0, 0, 0)
# Process the response
device._process_state_response(resp)

# Assert state is expected
Expand All @@ -191,6 +202,8 @@ def test_properties_missing_field(self) -> None:
# Construct and assert response
resp = Response.construct(TEST_RESPONSE)
self.assertIsNotNone(resp)

# Assert response is a state response
self.assertEqual(type(resp), PropertiesResponse)

# Process response
Expand Down

0 comments on commit 591783f

Please sign in to comment.