Skip to content
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
10 changes: 10 additions & 0 deletions miio/philips_bulb.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,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 PhilipsBulbException("Invalid brightness: %s" % brightness)

if cct < 1 or cct > 100:
raise PhilipsBulbException("Invalid color temperature: %s" % cct)

return self.send("set_bricct", [brightness, cct])

def delay_off(self, seconds: int):
"""Set delay off seconds."""

Expand Down
39 changes: 39 additions & 0 deletions miio/tests/test_philips_bulb.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def __init__(self, *args, **kwargs):
'set_cct': lambda x: self._set_state("cct", x),
'delay_off': lambda x: self._set_state("dv", x),
'apply_fixed_scene': lambda x: self._set_state("snm", x),
'set_bricct': lambda x: (
self._set_state('bright', [x[0]]),
self._set_state('cct', [x[1]])
)
}
super().__init__(args, kwargs)

Expand Down Expand Up @@ -102,6 +106,41 @@ def color_temperature():
with pytest.raises(PhilipsBulbException):
self.device.set_color_temperature(101)

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(PhilipsBulbException):
self.device.set_brightness_and_color_temperature(-1, 10)

with pytest.raises(PhilipsBulbException):
self.device.set_brightness_and_color_temperature(10, -1)

with pytest.raises(PhilipsBulbException):
self.device.set_brightness_and_color_temperature(0, 10)

with pytest.raises(PhilipsBulbException):
self.device.set_brightness_and_color_temperature(10, 0)

with pytest.raises(PhilipsBulbException):
self.device.set_brightness_and_color_temperature(101, 10)

with pytest.raises(PhilipsBulbException):
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
Expand Down