Skip to content

Commit

Permalink
Support for Xiaomi Vaccum Mop 2 Ultra and Pro+ (dreame) (#1356)
Browse files Browse the repository at this point in the history
* Added Xiaomi Vaccum Mop 2 Ultra and Pro+

* Updated automatic formatting using black

* Removed duplicated supported models

* Extended dreame test to test all supported models

* Added test for invalid dreame model

* Formatting by black

* import isort

* Updated readme with newly supported models
  • Loading branch information
2pirko authored Mar 19, 2022
1 parent 04eab3a commit c900b9e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Supported devices
- Xiaomi Walkingpad A1 (ksmb.walkingpad.v3)
- Xiaomi Smart Pet Water Dispenser (mmgg.pet_waterer.s1, s4)
- Xiaomi Mi Smart Humidifer S (jsqs, jsq5)
- Xiaomi Mi Robot Vacuum Mop 2 (Pro+, Ultra)


*Feel free to create a pull request to add support for new devices as
Expand Down
15 changes: 14 additions & 1 deletion miio/integrations/vacuum/dreame/dreamevacuum_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
DREAME_F9 = "dreame.vacuum.p2008"
DREAME_D9 = "dreame.vacuum.p2009"
DREAME_Z10_PRO = "dreame.vacuum.p2028"
DREAME_MOP_2_PRO_PLUS = "dreame.vacuum.p2041o"
DREAME_MOP_2_ULTRA = "dreame.vacuum.p2150a"


_DREAME_1C_MAPPING: MiotMapping = {
Expand Down Expand Up @@ -70,6 +72,8 @@
# https://home.miot-spec.com/spec/dreame.vacuum.p2008
# https://home.miot-spec.com/spec/dreame.vacuum.p2009
# https://home.miot-spec.com/spec/dreame.vacuum.p2028
# https://home.miot-spec.com/spec/dreame.vacuum.p2041o
# https://home.miot-spec.com/spec/dreame.vacuum.p2150a
"battery_level": {"siid": 3, "piid": 1},
"charging_state": {"siid": 3, "piid": 2},
"device_fault": {"siid": 2, "piid": 2},
Expand Down Expand Up @@ -115,6 +119,8 @@
DREAME_F9: _DREAME_F9_MAPPING,
DREAME_D9: _DREAME_F9_MAPPING,
DREAME_Z10_PRO: _DREAME_F9_MAPPING,
DREAME_MOP_2_PRO_PLUS: _DREAME_F9_MAPPING,
DREAME_MOP_2_ULTRA: _DREAME_F9_MAPPING,
}


Expand Down Expand Up @@ -184,8 +190,15 @@ def _get_cleaning_mode_enum_class(model):
"""Return cleaning mode enum class for model if found or None."""
if model == DREAME_1C:
return CleaningModeDreame1C
elif model in [DREAME_F9, DREAME_D9, DREAME_Z10_PRO]:
elif model in (
DREAME_F9,
DREAME_D9,
DREAME_Z10_PRO,
DREAME_MOP_2_PRO_PLUS,
DREAME_MOP_2_ULTRA,
):
return CleaningModeDreameF9
return None


class DreameVacuumStatus(DeviceStatusContainer):
Expand Down
15 changes: 15 additions & 0 deletions miio/integrations/vacuum/dreame/tests/test_dreamevacuum_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ..dreamevacuum_miot import (
DREAME_1C,
DREAME_F9,
MIOT_MAPPING,
ChargingState,
CleaningModeDreame1C,
CleaningModeDreameF9,
Expand Down Expand Up @@ -248,3 +249,17 @@ def test_waterflow_presets(self):
def test_waterflow(self):
value = self.device.waterflow()
assert value == {"Medium": 2}


@pytest.mark.parametrize("model", MIOT_MAPPING.keys())
def test_dreame_models(model: str):
vac = DreameVacuum(model=model)
# test _get_cleaning_mode_enum_class returns non-empty mapping
fp = vac.fan_speed_presets()
assert (fp is not None) and (len(fp) > 0)


def test_invalid_dreame_model():
vac = DreameVacuum(model="model.invalid")
fp = vac.fan_speed_presets()
assert fp == {}

0 comments on commit c900b9e

Please sign in to comment.