Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xiaomi Air Humidifier: Unavailable property "led" removed. #170

Merged
merged 3 commits into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions miio/airhumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class AirHumidifierStatus:
"""Container for status reports from the air humidifier."""

def __init__(self, data: Dict[str, Any]) -> None:
"""
Response of a Air Humidifier (zhimi.humidifier.v1):

{'power': 'off', 'mode': 'high', 'temp_dec': 294,
'humidity': 33, 'buzzer': 'on', 'led_b': 0}
"""

self.data = data

@property
Expand Down Expand Up @@ -57,11 +64,6 @@ def buzzer(self) -> bool:
"""True if buzzer is turned on."""
return self.data["buzzer"] == "on"

@property
def led(self) -> bool:
"""True if LED is turned on."""
return self.data["led"] == "on"

@property
def led_brightness(self) -> Optional[LedBrightness]:
"""LED brightness if available."""
Expand All @@ -71,9 +73,9 @@ def led_brightness(self) -> Optional[LedBrightness]:

def __str__(self) -> str:
s = "<AirHumidiferStatus power=%s, mode=%s, temperature=%s, " \
"humidity=%s%%, led=%s, led_brightness=%s, buzzer=%s>" % \
"humidity=%s%%, led_brightness=%s, buzzer=%s>" % \
(self.power, self.mode, self.temperature,
self.humidity, self.led, self.led_brightness, self.buzzer)
self.humidity, self.led_brightness, self.buzzer)
return s


Expand All @@ -84,7 +86,7 @@ def status(self) -> AirHumidifierStatus:
"""Retrieve properties."""

properties = ['power', 'mode', 'temp_dec', 'humidity', 'buzzer',
'led_b', 'led', ]
'led_b', ]

values = self.send(
"get_prop",
Expand Down Expand Up @@ -118,13 +120,6 @@ def set_led_brightness(self, brightness: LedBrightness):
"""Set led brightness."""
return self.send("set_led_b", [brightness.value])

def set_led(self, led: bool):
"""Turn led on/off."""
if led:
return self.send("set_led", ['on'])
else:
return self.send("set_led", ['off'])

def set_buzzer(self, buzzer: bool):
"""Set buzzer on/off."""
if buzzer:
Expand Down
13 changes: 0 additions & 13 deletions miio/tests/test_airhumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ def __init__(self, *args, **kwargs):
'temp_dec': 186,
'humidity': 62,
'buzzer': 'off',
'led': 'off',
'led_b': 2,
}
self.return_values = {
'get_prop': self._get_state,
'set_power': lambda x: self._set_state("power", x),
'set_mode': lambda x: self._set_state("mode", x),
'set_led': lambda x: self._set_state("led", x),
'set_led_b': lambda x: self._set_state("led_b", x),
'set_buzzer': lambda x: self._set_state("buzzer", x),
}
Expand Down Expand Up @@ -64,7 +62,6 @@ def test_status(self):
assert self.state().temperature == self.device.start_state["temp_dec"] / 10.0
assert self.state().humidity == self.device.start_state["humidity"]
assert self.state().mode == OperationMode(self.device.start_state["mode"])
assert self.state().led == (self.device.start_state["led"] == 'on')
assert self.state().led_brightness == LedBrightness(self.device.start_state["led_b"])
assert self.state().buzzer == (self.device.start_state["buzzer"] == 'on')

Expand Down Expand Up @@ -94,16 +91,6 @@ def led_brightness():
self.device.set_led_brightness(LedBrightness.Off)
assert led_brightness() == LedBrightness.Off

def test_set_led(self):
def led():
return self.device.status().led

self.device.set_led(True)
assert led() is True

self.device.set_led(False)
assert led() is False

def test_set_buzzer(self):
def buzzer():
return self.device.status().buzzer
Expand Down