Skip to content

Commit

Permalink
Philips Ceiling Lamp: New setter "bricct" added.
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi committed Feb 12, 2018
1 parent 665d0ab commit 5e9d606
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions miio/ceil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
40 changes: 40 additions & 0 deletions miio/tests/test_ceil.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest import TestCase
from miio import Ceil
from miio.ceil import CeilException
from .dummies import DummyDevice
import pytest

Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5e9d606

Please sign in to comment.