From 56358bcde1b9c12352741d7c406c1bf36863faf7 Mon Sep 17 00:00:00 2001 From: MPThLee Date: Mon, 14 Mar 2022 02:15:00 +0900 Subject: [PATCH 1/3] Add support for Air Purifier 4 (zhimi.airp.mb5) --- README.rst | 2 +- miio/airpurifier_miot.py | 6 ++++-- miio/tests/test_airpurifier_miot.py | 6 ++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index cd9eb212f..34d5fafe5 100644 --- a/README.rst +++ b/README.rst @@ -103,7 +103,7 @@ Supported devices - Xiaomi Mi Robot Vacuum V1, S4, S4 MAX, S5, S5 MAX, S6 Pure, M1S, S7 - Xiaomi Mi Home Air Conditioner Companion - Xiaomi Mi Smart Air Conditioner A (xiaomi.aircondition.mc1, mc2, mc4, mc5) -- Xiaomi Mi Air Purifier 2, 3H, 3C, Pro, Pro H, 4 Pro (zhimi.airpurifier.m2, mb3, mb4, v7, vb2, va2) +- Xiaomi Mi Air Purifier 2, 3H, 3C, 4, Pro, Pro H, 4 Pro (zhimi.airpurifier.m2, mb3, mb4, mb5, v7, vb2, va2) - Xiaomi Mi Air (Purifier) Dog X3, X5, X7SM (airdog.airpurifier.x3, airdog.airpurifier.x5, airdog.airpurifier.x7sm) - Xiaomi Mi Air Humidifier - Xiaomi Aqara Camera diff --git a/miio/airpurifier_miot.py b/miio/airpurifier_miot.py index ca8eace89..984882ed6 100644 --- a/miio/airpurifier_miot.py +++ b/miio/airpurifier_miot.py @@ -69,6 +69,7 @@ } # https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:air-purifier:0000A007:zhimi-va2:2 +# https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:air-purifier:0000A007:zhimi-mb5:1 _MAPPING_VA2 = { # Air Purifier "power": {"siid": 2, "piid": 1}, @@ -109,6 +110,7 @@ "zhimi.airpurifier.vb2": _MAPPING, # airpurifier proh "zhimi.airpurifier.mb4": _MAPPING_MB4, # airpurifier 3c "zhimi.airp.mb4a": _MAPPING_MB4, # airpurifier 3c + "zhimi.airp.mb5": _MAPPING_VA2, # airpurifier 4 "zhimi.airp.va2": _MAPPING_VA2, # airpurifier 4 pro } @@ -254,7 +256,7 @@ def led_brightness(self) -> Optional[LedBrightness]: value = self.data.get("led_brightness") if value is not None: - if self.model == "zhimi.airp.va2": + if self.model == "zhimi.airp.va2" or self.model == "zhimi.airp.mb5": value = 2 - value try: return LedBrightness(value) @@ -510,7 +512,7 @@ def set_led_brightness(self, brightness: LedBrightness): ) value = brightness.value - if self.model == "zhimi.airp.va2" and value: + if (self.model == "zhimi.airp.va2" or self.model == "zhimi.airp.mb5") and value: value = 2 - value return self.set_property("led_brightness", value) diff --git a/miio/tests/test_airpurifier_miot.py b/miio/tests/test_airpurifier_miot.py index ce83897e2..2a2d9ff61 100644 --- a/miio/tests/test_airpurifier_miot.py +++ b/miio/tests/test_airpurifier_miot.py @@ -304,6 +304,12 @@ def __init__(self, *args, **kwargs): self.state = _INITIAL_STATE_VA2 super().__init__(*args, **kwargs) +class DummyAirPurifierMiotMB5(DummyAirPurifierMiot): + def __init__(self, *args, **kwargs): + self._model = "zhimi.airp.mb5" + self.state = _INITIAL_STATE_VA2 + super().__init__(*args, **kwargs) + @pytest.fixture(scope="function") def airpurifierVA2(request): From dc3005c81102703a106f2712de06cc107d40a7d3 Mon Sep 17 00:00:00 2001 From: MPThLee Date: Mon, 14 Mar 2022 02:30:06 +0900 Subject: [PATCH 2/3] fix: formatting --- miio/airpurifier_miot.py | 4 ++-- miio/tests/test_airpurifier_miot.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/miio/airpurifier_miot.py b/miio/airpurifier_miot.py index 984882ed6..2476221d5 100644 --- a/miio/airpurifier_miot.py +++ b/miio/airpurifier_miot.py @@ -256,7 +256,7 @@ def led_brightness(self) -> Optional[LedBrightness]: value = self.data.get("led_brightness") if value is not None: - if self.model == "zhimi.airp.va2" or self.model == "zhimi.airp.mb5": + if self.model in ("zhimi.airp.va2", "zhimi.airp.mb5"): value = 2 - value try: return LedBrightness(value) @@ -512,7 +512,7 @@ def set_led_brightness(self, brightness: LedBrightness): ) value = brightness.value - if (self.model == "zhimi.airp.va2" or self.model == "zhimi.airp.mb5") and value: + if self.model in ("zhimi.airp.va2", "zhimi.airp.mb5") and value: value = 2 - value return self.set_property("led_brightness", value) diff --git a/miio/tests/test_airpurifier_miot.py b/miio/tests/test_airpurifier_miot.py index 2a2d9ff61..26e5481cd 100644 --- a/miio/tests/test_airpurifier_miot.py +++ b/miio/tests/test_airpurifier_miot.py @@ -304,6 +304,7 @@ def __init__(self, *args, **kwargs): self.state = _INITIAL_STATE_VA2 super().__init__(*args, **kwargs) + class DummyAirPurifierMiotMB5(DummyAirPurifierMiot): def __init__(self, *args, **kwargs): self._model = "zhimi.airp.mb5" From 0e15ca15b60b5daa213fe9d7f13dcb3a13982374 Mon Sep 17 00:00:00 2001 From: MPThLee Date: Mon, 14 Mar 2022 02:39:37 +0900 Subject: [PATCH 3/3] fix: trailing whitespace --- miio/airpurifier_miot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miio/airpurifier_miot.py b/miio/airpurifier_miot.py index 2476221d5..e08f02e75 100644 --- a/miio/airpurifier_miot.py +++ b/miio/airpurifier_miot.py @@ -110,7 +110,7 @@ "zhimi.airpurifier.vb2": _MAPPING, # airpurifier proh "zhimi.airpurifier.mb4": _MAPPING_MB4, # airpurifier 3c "zhimi.airp.mb4a": _MAPPING_MB4, # airpurifier 3c - "zhimi.airp.mb5": _MAPPING_VA2, # airpurifier 4 + "zhimi.airp.mb5": _MAPPING_VA2, # airpurifier 4 "zhimi.airp.va2": _MAPPING_VA2, # airpurifier 4 pro }