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

Philips Moonlight: Align signature of set_brightness_and_rgb #430

Merged
merged 1 commit into from
Dec 8, 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
11 changes: 6 additions & 5 deletions miio/philips_moonlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,20 @@ def set_brightness_and_color_temperature(self, brightness: int, cct: int):

@command(
click.argument("brightness", type=int),
click.argument("rgb", type=int),
click.argument("rgb", default=[255] * 3, type=click.Tuple([int, int, int])),
default_output=format_output(
"Setting brightness to {brightness} and color to {rgb}")
)
def set_brightness_and_rgb(self, brightness: int, rgb: int):
def set_brightness_and_rgb(self, brightness: int, rgb: Tuple[int, int, int]):
"""Set brightness level and the color."""
if brightness < 1 or brightness > 100:
raise PhilipsMoonlightException("Invalid brightness: %s" % brightness)

if rgb < 0 or rgb > 16777215:
raise PhilipsMoonlightException("Invalid color: %s" % rgb)
for color in rgb:
if color < 0 or color > 255:
raise PhilipsMoonlightException("Invalid color: %s" % color)

return self.send("set_brirgb", [brightness, rgb])
return self.send("set_brirgb", [brightness, rgb_to_int(rgb)])

@command(
click.argument("number", type=int),
Expand Down
28 changes: 21 additions & 7 deletions miio/tests/test_philips_moonlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,30 +192,44 @@ def brightness():
def rgb():
return self.device.status().rgb

self.device.set_brightness_and_rgb(20, 0)
self.device.set_brightness_and_rgb(20, (0, 0, 0))
assert brightness() == 20
assert rgb() == (0, 0, 0)
self.device.set_brightness_and_rgb(31, 16711680)
self.device.set_brightness_and_rgb(31, (255, 0, 0))
assert brightness() == 31
assert rgb() == (255, 0, 0)
self.device.set_brightness_and_rgb(100, 16777215)
self.device.set_brightness_and_rgb(100, (255, 255, 255))
assert brightness() == 100
assert rgb() == (255, 255, 255)

with pytest.raises(PhilipsMoonlightException):
self.device.set_brightness_and_rgb(-1, 10)

with pytest.raises(PhilipsMoonlightException):
self.device.set_brightness_and_rgb(10, -1)

with pytest.raises(PhilipsMoonlightException):
self.device.set_brightness_and_rgb(0, 10)

with pytest.raises(PhilipsMoonlightException):
self.device.set_brightness_and_rgb(101, 10)

with pytest.raises(PhilipsMoonlightException):
self.device.set_brightness_and_rgb(10, 16777216)
self.device.set_brightness_and_rgb(10, (-1, 0, 0))

with pytest.raises(PhilipsMoonlightException):
self.device.set_brightness_and_rgb(10, (256, 0, 0))

with pytest.raises(PhilipsMoonlightException):
self.device.set_brightness_and_rgb(10, (0, -1, 0))

with pytest.raises(PhilipsMoonlightException):
self.device.set_brightness_and_rgb(10, (0, 256, 0))

with pytest.raises(PhilipsMoonlightException):
self.device.set_brightness_and_rgb(10, (0, 0, -1))

with pytest.raises(PhilipsMoonlightException):
self.device.set_brightness_and_rgb(10, (0, 0, 256))



def test_set_scene(self):
def scene():
Expand Down