From b0c04cfef7512568f2a6004ff1a04dbb9c414a48 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sun, 28 Jan 2018 21:41:24 +0100 Subject: [PATCH] SleepMode enum added. SleepMode isn't a subset of OperationMode. (#190) --- miio/airpurifier.py | 10 ++++++++-- miio/tests/test_airpurifier.py | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/miio/airpurifier.py b/miio/airpurifier.py index b032dda92..818cc0481 100644 --- a/miio/airpurifier.py +++ b/miio/airpurifier.py @@ -19,6 +19,12 @@ class OperationMode(enum.Enum): Idle = 'idle' +class SleepMode(enum.Enum): + Off = 'poweroff' + Silent = 'silent' + Idle = 'idle' + + class LedBrightness(enum.Enum): Bright = 0 Dim = 1 @@ -112,10 +118,10 @@ def mode(self) -> OperationMode: return OperationMode(self.data["mode"]) @property - def sleep_mode(self) -> Optional[OperationMode]: + def sleep_mode(self) -> Optional[SleepMode]: """Operation mode of the sleep state. (Idle vs. Silent)""" if self.data["sleep_mode"] is not None: - return OperationMode(self.data["sleep_mode"]) + return SleepMode(self.data["sleep_mode"]) return None diff --git a/miio/tests/test_airpurifier.py b/miio/tests/test_airpurifier.py index 220557972..b6d383fd7 100644 --- a/miio/tests/test_airpurifier.py +++ b/miio/tests/test_airpurifier.py @@ -1,7 +1,7 @@ from unittest import TestCase from miio import AirPurifier from miio.airpurifier import ( - OperationMode, LedBrightness, FilterType, AirPurifierException + OperationMode, LedBrightness, FilterType, SleepMode, AirPurifierException ) from .dummies import DummyDevice import pytest @@ -114,7 +114,7 @@ def test_status(self): assert self.state().illuminance == self.device.start_state["bright"] assert self.state().volume == self.device.start_state["volume"] assert self.state().filter_rfid_product_id == self.device.start_state["rfid_product_id"] - assert self.state().sleep_mode == OperationMode(self.device.start_state["sleep_mode"]) + assert self.state().sleep_mode == SleepMode(self.device.start_state["sleep_mode"]) assert self.state().sleep_time == self.device.start_state["sleep_time"] assert self.state().sleep_mode_learn_count == self.device.start_state["sleep_data_num"] assert self.state().extra_features == self.device.start_state["app_extra"]