Skip to content

Commit

Permalink
Air Conditioning Companion: Swing mode property returns the enum now (r…
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi authored Mar 19, 2018
1 parent 67591ab commit 1c46795
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 7 additions & 3 deletions miio/airconditioningcompanion.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,13 @@ def target_temperature(self) -> Optional[int]:
return None

@property
def swing_mode(self) -> bool:
"""True if swing mode is enabled."""
return int(self.data[1][5:6]) == SwingMode.On.value
def swing_mode(self) -> Optional[SwingMode]:
"""Current swing mode."""
try:
mode = int(self.data[1][5:6])
return SwingMode(mode)
except TypeError:
return None

@property
def fan_speed(self) -> Optional[FanSpeed]:
Expand Down
7 changes: 6 additions & 1 deletion miio/tests/test_airconditioningcompanion.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_status(self):
assert self.state().load_power == 2
assert self.state().air_condition_model == '010500978022222102'
assert self.state().target_temperature == 25
assert self.state().swing_mode is False
assert self.state().swing_mode == SwingMode.Off
assert self.state().fan_speed == FanSpeed.Low
assert self.state().mode == OperationMode.Auto
assert self.state().led == 'off'
Expand All @@ -94,6 +94,11 @@ def test_status_without_target_temperature(self):
self.device.state[1] = None
assert self.state().target_temperature is None

def test_status_without_swing_mode(self):
self.device._reset_state()
self.device.state[1] = None
assert self.state().swing_mode is None

def test_status_without_mode(self):
self.device._reset_state()
self.device.state[1] = None
Expand Down

0 comments on commit 1c46795

Please sign in to comment.