From d259bd87ecc9619a4ebe4c925e5bbdb3a0c0b0a2 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sat, 8 Dec 2018 10:46:27 +0100 Subject: [PATCH] Update signature of set_brightness_and_rgb --- miio/philips_moonlight.py | 11 ++++++----- miio/tests/test_philips_moonlight.py | 28 +++++++++++++++++++++------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/miio/philips_moonlight.py b/miio/philips_moonlight.py index 1faf60535..bf71fbc74 100644 --- a/miio/philips_moonlight.py +++ b/miio/philips_moonlight.py @@ -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), diff --git a/miio/tests/test_philips_moonlight.py b/miio/tests/test_philips_moonlight.py index 77f4a79c9..f7596fa33 100644 --- a/miio/tests/test_philips_moonlight.py +++ b/miio/tests/test_philips_moonlight.py @@ -192,22 +192,19 @@ 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) @@ -215,7 +212,24 @@ def rgb(): 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():