Skip to content

Commit

Permalink
Air Humidifier: Add set_led method (#451)
Browse files Browse the repository at this point in the history
* Air Humidifier: Add set_led method

* Fix tests
  • Loading branch information
syssi authored and rytilahti committed Jan 9, 2019
1 parent 2774aa5 commit 474b1d1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions miio/airhumidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,20 @@ def set_led_brightness(self, brightness: LedBrightness):

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

0 comments on commit 474b1d1

Please sign in to comment.