Skip to content

Commit

Permalink
Add support for Air Purifier 4 (zhimi.airp.mb5) (#1357)
Browse files Browse the repository at this point in the history
* Add support for Air Purifier 4 (zhimi.airp.mb5)

* fix: formatting

* fix: trailing whitespace
  • Loading branch information
MPThLee authored Mar 14, 2022
1 parent af1e31a commit 36568cb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions miio/airpurifier_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 in ("zhimi.airp.va2", "zhimi.airp.mb5"):
value = 2 - value
try:
return LedBrightness(value)
Expand Down Expand Up @@ -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 in ("zhimi.airp.va2", "zhimi.airp.mb5") and value:
value = 2 - value
return self.set_property("led_brightness", value)

Expand Down
7 changes: 7 additions & 0 deletions miio/tests/test_airpurifier_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,13 @@ def __init__(self, *args, **kwargs):
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):
request.cls.device = DummyAirPurifierMiotVA2()
Expand Down

0 comments on commit 36568cb

Please sign in to comment.