Skip to content

Commit

Permalink
Bases supported features on device attributes rather than name (#162)
Browse files Browse the repository at this point in the history
* Base supported features on device attributes rather than name

* Add can_set_dimmer

* Add test

* Add test for Philips bulb

* Formatting
  • Loading branch information
Hate-Usernames authored and Patrik committed May 1, 2018
1 parent 5e6eaad commit a702261
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
12 changes: 10 additions & 2 deletions pytradfri/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,21 @@ class LightControl:
def __init__(self, device):
self._device = device

self.can_set_dimmer = None
self.can_set_temp = None
self.can_set_xy = None
self.can_set_color = None

if 'WS' in self._device.device_info.model_number:
if ATTR_LIGHT_DIMMER in self.raw[0]:
self.can_set_dimmer = True

if ATTR_LIGHT_MIREDS in self.raw[0]:
self.can_set_temp = True

if 'CWS' in self._device.device_info.model_number:
if ATTR_LIGHT_COLOR_X in self.raw[0]:
self.can_set_xy = True

if ATTR_LIGHT_COLOR_HUE in self.raw[0]:
self.can_set_color = True

self.min_mireds = RANGE_MIREDS[0]
Expand Down
32 changes: 32 additions & 0 deletions tests/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,38 @@
'9054': 0,
}

# Retrieved from Gateway running on 1.3.14
LIGHT_PHILIPS = {
'3': {
'0': 'Philips',
'1': 'LCT012',
'2': '',
'3': '1.15.2_r19181',
'6': 1
},
'3311': [
{
'5706': '0',
'5707': 13653,
'5708': 0,
'5709': 20413,
'5710': 21477,
'5711': 0,
'5717': 0,
'5850': 1,
'5851': 254,
'9003': 0
}
],
'5750': 2,
'9001': 'Hue Bulb',
'9002': 1524306939,
'9003': 65551,
'9019': 1,
'9020': 1525025378,
'9054': 0
}

# Retrieved from Gateway running on 1.2.42
REMOTE_CONTROL = {
'3': {'0': 'IKEA of Sweden',
Expand Down
28 changes: 27 additions & 1 deletion tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ROOT_DEVICES, ATTR_NAME, ATTR_LIGHT_CONTROL, ATTR_LAST_SEEN)
from pytradfri.device import Device
from devices import (
LIGHT_W, LIGHT_WS, LIGHT_CWS, REMOTE_CONTROL, MOTION_SENSOR)
LIGHT_W, LIGHT_WS, LIGHT_CWS, LIGHT_PHILIPS, REMOTE_CONTROL, MOTION_SENSOR)


def test_device_properties():
Expand Down Expand Up @@ -160,6 +160,32 @@ def test_has_light_control():
assert dev.has_light_control is False


def test_supported_features():
dev = Device(LIGHT_WS)
assert dev.light_control.can_set_dimmer is True
assert dev.light_control.can_set_temp is True
assert dev.light_control.can_set_xy is True
assert dev.light_control.can_set_color is None

dev = Device(LIGHT_CWS)
assert dev.light_control.can_set_dimmer is True
assert dev.light_control.can_set_temp is None
assert dev.light_control.can_set_xy is True
assert dev.light_control.can_set_color is True

dev = Device(LIGHT_W)
assert dev.light_control.can_set_dimmer is True
assert dev.light_control.can_set_temp is None
assert dev.light_control.can_set_xy is None
assert dev.light_control.can_set_color is None

dev = Device(LIGHT_PHILIPS)
assert dev.light_control.can_set_dimmer is True
assert dev.light_control.can_set_temp is True
assert dev.light_control.can_set_xy is True
assert dev.light_control.can_set_color is True


def test_last_seen():
dev = Device(LIGHT_WS)
assert dev.last_seen is not None
Expand Down

0 comments on commit a702261

Please sign in to comment.