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

Air Humidifier: Add set_led method #451

Merged
merged 2 commits into from
Jan 9, 2019
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
14 changes: 14 additions & 0 deletions miio/airhumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,20 @@ def set_led_brightness(self, brightness: LedBrightness):
"""Set led brightness."""
return self.send("set_led_b", [brightness.value])

@command(
click.argument("led", type=bool),
default_output=format_output(
lambda led: "Turning on LED"
if led else "Turning off LED"
)
)
def set_led(self, led: bool):
"""Turn led on/off."""
if led:
return self.set_led_brightness(LedBrightness.Bright)
else:
return self.set_led_brightness(LedBrightness.Off)

@command(
click.argument("buzzer", type=bool),
default_output=format_output(
Expand Down
20 changes: 20 additions & 0 deletions miio/tests/test_airhumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ def led_brightness():
self.device.set_led_brightness(LedBrightness.Off)
assert led_brightness() == LedBrightness.Off

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

self.device.set_led(True)
assert led_brightness() == LedBrightness.Bright

self.device.set_led(False)
assert led_brightness() == LedBrightness.Off

def test_set_buzzer(self):
def buzzer():
return self.device.status().buzzer
Expand Down Expand Up @@ -343,6 +353,16 @@ def led_brightness():
self.device.set_led_brightness(LedBrightness.Off)
assert led_brightness() == LedBrightness.Off

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

self.device.set_led(True)
assert led_brightness() == LedBrightness.Bright

self.device.set_led(False)
assert led_brightness() == LedBrightness.Off

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