Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Philips Ceiling Lamp: New setter "bricct" added #216

Merged
merged 1 commit into from
Feb 12, 2018
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/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