From 1c46795c3763401d65fbca8c42868469b71ff893 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Mon, 19 Mar 2018 08:11:47 +0100 Subject: [PATCH] Air Conditioning Companion: Swing mode property returns the enum now (#274) --- miio/airconditioningcompanion.py | 10 +++++++--- miio/tests/test_airconditioningcompanion.py | 7 ++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/miio/airconditioningcompanion.py b/miio/airconditioningcompanion.py index 7f6500f49..eee5ac727 100644 --- a/miio/airconditioningcompanion.py +++ b/miio/airconditioningcompanion.py @@ -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]: diff --git a/miio/tests/test_airconditioningcompanion.py b/miio/tests/test_airconditioningcompanion.py index f9e5e313d..c9b2cdb65 100644 --- a/miio/tests/test_airconditioningcompanion.py +++ b/miio/tests/test_airconditioningcompanion.py @@ -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' @@ -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