Skip to content

Commit

Permalink
Merge 392be2b into c38b21b
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi committed Jan 28, 2018
2 parents c38b21b + 392be2b commit 1431c22
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
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

0 comments on commit 1431c22

Please sign in to comment.