Skip to content

Commit

Permalink
Update signature of set_brightness_and_rgb (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi authored and rytilahti committed Dec 8, 2018
1 parent 17d2420 commit cff835c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
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

0 comments on commit cff835c

Please sign in to comment.