From 5e9d6064ce8c6ce56440d77b96960072daa162f3 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Mon, 12 Feb 2018 16:21:31 +0100 Subject: [PATCH] Philips Ceiling Lamp: New setter "bricct" added. --- miio/ceil.py | 10 ++++++++++ miio/tests/test_ceil.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/miio/ceil.py b/miio/ceil.py index 46004fbb4..fc539248e 100644 --- a/miio/ceil.py +++ b/miio/ceil.py @@ -117,6 +117,16 @@ def set_color_temperature(self, level: int): return self.send("set_cct", [level]) + def set_brightness_and_color_temperature(self, brightness: int, cct: int): + """Set brightness level and the correlated color temperature.""" + if brightness < 1 or brightness > 100: + raise CeilException("Invalid brightness: %s" % brightness) + + if cct < 1 or cct > 100: + raise CeilException("Invalid color temperature: %s" % cct) + + return self.send("set_bricct", [brightness, cct]) + def delay_off(self, seconds: int): """Turn off delay in seconds.""" diff --git a/miio/tests/test_ceil.py b/miio/tests/test_ceil.py index 9fd0d64d2..28084509c 100644 --- a/miio/tests/test_ceil.py +++ b/miio/tests/test_ceil.py @@ -1,5 +1,6 @@ from unittest import TestCase from miio import Ceil +from miio.ceil import CeilException from .dummies import DummyDevice import pytest @@ -26,6 +27,10 @@ def __init__(self, *args, **kwargs): 'enable_bl': lambda x: self._set_state("bl", x), 'enable_ac': lambda x: self._set_state("ac", x), 'set_cct': lambda x: self._set_state("cct", x), + 'set_bricct': lambda x: ( + self._set_state('bright', [x[0]]), + self._set_state('cct', [x[1]]) + ), } super().__init__(args, kwargs) @@ -89,6 +94,41 @@ def color_temperature(): self.device.set_color_temperature(20) assert color_temperature() == 20 + def test_set_brightness_and_color_temperature(self): + def color_temperature(): + return self.device.status().color_temperature + + def brightness(): + return self.device.status().brightness + + self.device.set_brightness_and_color_temperature(20, 21) + assert brightness() == 20 + assert color_temperature() == 21 + self.device.set_brightness_and_color_temperature(31, 30) + assert brightness() == 31 + assert color_temperature() == 30 + self.device.set_brightness_and_color_temperature(10, 11) + assert brightness() == 10 + assert color_temperature() == 11 + + with pytest.raises(CeilException): + self.device.set_brightness_and_color_temperature(-1, 10) + + with pytest.raises(CeilException): + self.device.set_brightness_and_color_temperature(10, -1) + + with pytest.raises(CeilException): + self.device.set_brightness_and_color_temperature(0, 10) + + with pytest.raises(CeilException): + self.device.set_brightness_and_color_temperature(10, 0) + + with pytest.raises(CeilException): + self.device.set_brightness_and_color_temperature(101, 10) + + with pytest.raises(CeilException): + self.device.set_brightness_and_color_temperature(10, 101) + def test_delay_off(self): def delay_off_countdown(): return self.device.status().delay_off_countdown