From 7bb60068d7a38fd45b20ecb95dca920bcee9043e Mon Sep 17 00:00:00 2001 From: shred86 <32663154+shred86@users.noreply.github.com> Date: Thu, 11 Oct 2018 22:47:14 -0800 Subject: [PATCH] Color control for Abode RGB lights (#17347) * Color control support for Abode lights * Updated add_devices to add_entities * Update line length * Changed elif to if for pylint warning --- homeassistant/components/light/abode.py | 33 ++++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/light/abode.py b/homeassistant/components/light/abode.py index 69314b63a4b..397d61f3073 100644 --- a/homeassistant/components/light/abode.py +++ b/homeassistant/components/light/abode.py @@ -8,9 +8,10 @@ import logging from math import ceil from homeassistant.components.abode import AbodeDevice, DOMAIN as ABODE_DOMAIN from homeassistant.components.light import ( - ATTR_BRIGHTNESS, ATTR_HS_COLOR, - SUPPORT_BRIGHTNESS, SUPPORT_COLOR, Light) -import homeassistant.util.color as color_util + ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_COLOR_TEMP, + SUPPORT_BRIGHTNESS, SUPPORT_COLOR, SUPPORT_COLOR_TEMP, Light) +from homeassistant.util.color import ( + color_temperature_kelvin_to_mired, color_temperature_mired_to_kelvin) DEPENDENCIES = ['abode'] @@ -45,10 +46,13 @@ class AbodeLight(AbodeDevice, Light): def turn_on(self, **kwargs): """Turn on the light.""" - if (ATTR_HS_COLOR in kwargs and - self._device.is_dimmable and self._device.has_color): - self._device.set_color(color_util.color_hs_to_RGB( - *kwargs[ATTR_HS_COLOR])) + if ATTR_COLOR_TEMP in kwargs and self._device.is_color_capable: + self._device.set_color_temp( + int(color_temperature_mired_to_kelvin( + kwargs[ATTR_COLOR_TEMP]))) + + if ATTR_HS_COLOR in kwargs and self._device.is_color_capable: + self._device.set_color(kwargs[ATTR_HS_COLOR]) if ATTR_BRIGHTNESS in kwargs and self._device.is_dimmable: # Convert HASS brightness (0-255) to Abode brightness (0-99) @@ -77,18 +81,23 @@ class AbodeLight(AbodeDevice, Light): # Convert Abode brightness (0-99) to HASS brightness (0-255) return ceil(brightness * 255 / 99.0) + @property + def color_temp(self): + """Return the color temp of the light.""" + if self._device.has_color: + return color_temperature_kelvin_to_mired(self._device.color_temp) + @property def hs_color(self): """Return the color of the light.""" - if self._device.is_dimmable and self._device.has_color: - return color_util.color_RGB_to_hs(*self._device.color) + if self._device.has_color: + return self._device.color @property def supported_features(self): """Flag supported features.""" - if self._device.is_dimmable and self._device.has_color: - return SUPPORT_BRIGHTNESS | SUPPORT_COLOR + if self._device.is_dimmable and self._device.is_color_capable: + return SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_COLOR_TEMP if self._device.is_dimmable: return SUPPORT_BRIGHTNESS - return 0