From a702261e09092bebd62556694d8cb8f198917ea2 Mon Sep 17 00:00:00 2001 From: Hate-Usernames Date: Tue, 1 May 2018 08:20:49 +0100 Subject: [PATCH] Bases supported features on device attributes rather than name (#162) * Base supported features on device attributes rather than name * Add can_set_dimmer * Add test * Add test for Philips bulb * Formatting --- pytradfri/device.py | 12 ++++++++++-- tests/devices.py | 32 ++++++++++++++++++++++++++++++++ tests/test_device.py | 28 +++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/pytradfri/device.py b/pytradfri/device.py index fd6c0bb7..0a7d70b9 100644 --- a/pytradfri/device.py +++ b/pytradfri/device.py @@ -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] diff --git a/tests/devices.py b/tests/devices.py index c05f0317..d1872fba 100644 --- a/tests/devices.py +++ b/tests/devices.py @@ -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', diff --git a/tests/test_device.py b/tests/test_device.py index d1c448f5..a515379f 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -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(): @@ -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