Skip to content

Commit

Permalink
Add clean mode (new feature) to the zhimi.humidifier.ca4 (rytilahti#907)
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi authored Jan 13, 2021
1 parent 49c3916 commit fb1aee8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
25 changes: 23 additions & 2 deletions miio/airhumidifier_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# Other (siid=7)
"actual_speed": {"siid": 7, "piid": 1}, # [0, 2000] step 1
"power_time": {"siid": 7, "piid": 3}, # [0, 4294967295] step 1
"clean_mode": {"siid": 7, "piid": 5}, # bool
}


Expand Down Expand Up @@ -199,6 +200,11 @@ def power_time(self) -> int:
"""Return how long the device has been powered in seconds."""
return self.data["power_time"]

@property
def clean_mode(self) -> bool:
"""Return True if clean mode is active."""
return self.data["clean_mode"]

def __repr__(self) -> str:
s = (
"<AirHumidifierMiotStatus"
Expand All @@ -218,7 +224,8 @@ def __repr__(self) -> str:
"led_brightness=%s, "
"child_lock=%s, "
"actual_speed=%s, "
"power_time=%s>"
"power_time=%s, "
"clean_mode=%s>"
% (
self.power,
self.fault,
Expand All @@ -237,6 +244,7 @@ def __repr__(self) -> str:
self.child_lock,
self.actual_speed,
self.power_time,
self.clean_mode,
)
)
return s
Expand Down Expand Up @@ -274,7 +282,8 @@ def __init__(
"Target motor speed: {result.motor_speed} rpm\n"
"Actual motor speed: {result.actual_speed} rpm\n"
"Use time: {result.use_time} s\n"
"Power time: {result.power_time} s\n",
"Power time: {result.power_time} s\n"
"Clean mode: {result.clean_mode}\n",
)
)
def status(self) -> AirHumidifierMiotStatus:
Expand Down Expand Up @@ -367,3 +376,15 @@ def set_child_lock(self, lock: bool):
def set_dry(self, dry: bool):
"""Set dry mode on/off."""
return self.set_property("dry", dry)

@command(
click.argument("clean_mode", type=bool),
default_output=format_output(
lambda clean_mode: "Turning on clean mode"
if clean_mode
else "Turning off clean mode"
),
)
def set_clean_mode(self, clean_mode: bool):
"""Set clean mode on/off."""
return self.set_property("clean_mode", clean_mode)
12 changes: 12 additions & 0 deletions miio/tests/test_airhumidifier_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"motor_speed": 354,
"actual_speed": 820,
"power_time": 4272468,
"clean_mode": False,
}


Expand All @@ -47,6 +48,7 @@ def __init__(self, *args, **kwargs):
"set_buzzer": lambda x: self._set_state("buzzer", x),
"set_child_lock": lambda x: self._set_state("child_lock", x),
"set_dry": lambda x: self._set_state("dry", x),
"set_clean_mode": lambda x: self._set_state("clean_mode", x),
}
super().__init__(*args, **kwargs)

Expand Down Expand Up @@ -180,3 +182,13 @@ def dry():

self.device.set_dry(False)
assert dry() is False

def test_set_clean_mode(self):
def clean_mode():
return self.device.status().clean_mode

self.device.set_clean_mode(True)
assert clean_mode() is True

self.device.set_clean_mode(False)
assert clean_mode() is False

0 comments on commit fb1aee8

Please sign in to comment.