From dc71c194c25d26d6af378fb639ba157a28f2479c Mon Sep 17 00:00:00 2001 From: Daniyar Yeralin Date: Fri, 26 Jul 2019 17:35:34 -0400 Subject: [PATCH 1/3] Introduce support for color temperature --- homeassistant/components/flux_led/light.py | 31 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/flux_led/light.py b/homeassistant/components/flux_led/light.py index 38809e94c92c98..65652f7d4c08c6 100644 --- a/homeassistant/components/flux_led/light.py +++ b/homeassistant/components/flux_led/light.py @@ -9,9 +9,9 @@ from homeassistant.const import CONF_DEVICES, CONF_NAME, CONF_PROTOCOL from homeassistant.components.light import ( - ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_EFFECT, ATTR_WHITE_VALUE, + ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_EFFECT, ATTR_WHITE_VALUE, ATTR_COLOR_TEMP, EFFECT_COLORLOOP, EFFECT_RANDOM, SUPPORT_BRIGHTNESS, SUPPORT_EFFECT, - SUPPORT_COLOR, SUPPORT_WHITE_VALUE, Light, PLATFORM_SCHEMA) + SUPPORT_COLOR, SUPPORT_WHITE_VALUE, SUPPORT_COLOR_TEMP, Light, PLATFORM_SCHEMA) import homeassistant.helpers.config_validation as cv import homeassistant.util.color as color_util @@ -27,7 +27,7 @@ DOMAIN = 'flux_led' SUPPORT_FLUX_LED = (SUPPORT_BRIGHTNESS | SUPPORT_EFFECT | - SUPPORT_COLOR) + SUPPORT_COLOR | SUPPORT_COLOR_TEMP) MODE_RGB = 'rgb' MODE_RGBW = 'rgbw' @@ -36,6 +36,11 @@ # RGB value is ignored when this mode is specified. MODE_WHITE = 'w' +# Constant color temp values for 2 flux_led special modes +# Warm-white and Cool-white. Details on #23704 +COLOR_TEMP_WARM_WHITE = 333 +COLOR_TEMP_COOL_WHITE = 250 + # List of supported effects which aren't already declared in LIGHT EFFECT_RED_FADE = 'red_fade' EFFECT_GREEN_FADE = 'green_fade' @@ -264,13 +269,14 @@ async def async_turn_on(self, **kwargs): def _turn_on(self, **kwargs): """Turn the specified or all lights on.""" self._bulb.turnOn() - + hs_color = kwargs.get(ATTR_HS_COLOR) brightness = kwargs.get(ATTR_BRIGHTNESS) effect = kwargs.get(ATTR_EFFECT) white = kwargs.get(ATTR_WHITE_VALUE) + color_temp = kwargs.get(ATTR_COLOR_TEMP) - if all(item is None for item in [hs_color, brightness, effect, white]): + if all(item is None for item in [hs_color, brightness, effect, white, color_temp]): return # handle W only mode (use brightness instead of white value) @@ -278,6 +284,8 @@ def _turn_on(self, **kwargs): if brightness is not None: self._bulb.setWarmWhite255(brightness) return + + # handle effects if effect is not None: # Random color effect if effect == EFFECT_RANDOM: @@ -294,6 +302,19 @@ def _turn_on(self, **kwargs): elif effect in EFFECT_MAP: self._bulb.setPresetPattern(EFFECT_MAP[effect], 50) return + + # handle special modes + if color_temp is not None: + if brightness is None: + brightness = self.brightness + if color_temp == COLOR_TEMP_WARM_WHITE: + self._bulb.setRgbw(w=brightness) + elif color_temp == COLOR_TEMP_COOL_WHITE: + self._bulb.setRgbw(w2=brightness) + else: + self._bulb.setRgbw(*color_util.color_temperature_to_rgb(color_temp)) + return + # Preserve current brightness on color/white level change if hs_color is not None: if brightness is None: From 37b9bc249bd62d89cd78c1cea6a86653ea8bb567 Mon Sep 17 00:00:00 2001 From: Daniyar Yeralin Date: Wed, 31 Jul 2019 10:07:15 -0400 Subject: [PATCH 2/3] Fix linter errors --- homeassistant/components/flux_led/light.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/flux_led/light.py b/homeassistant/components/flux_led/light.py index 65652f7d4c08c6..c5f6c3f967e194 100644 --- a/homeassistant/components/flux_led/light.py +++ b/homeassistant/components/flux_led/light.py @@ -9,9 +9,10 @@ from homeassistant.const import CONF_DEVICES, CONF_NAME, CONF_PROTOCOL from homeassistant.components.light import ( - ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_EFFECT, ATTR_WHITE_VALUE, ATTR_COLOR_TEMP, - EFFECT_COLORLOOP, EFFECT_RANDOM, SUPPORT_BRIGHTNESS, SUPPORT_EFFECT, - SUPPORT_COLOR, SUPPORT_WHITE_VALUE, SUPPORT_COLOR_TEMP, Light, PLATFORM_SCHEMA) + ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_EFFECT, ATTR_WHITE_VALUE, + ATTR_COLOR_TEMP, EFFECT_COLORLOOP, EFFECT_RANDOM, SUPPORT_BRIGHTNESS, + SUPPORT_EFFECT, SUPPORT_COLOR, SUPPORT_WHITE_VALUE, SUPPORT_COLOR_TEMP, + Light, PLATFORM_SCHEMA) import homeassistant.helpers.config_validation as cv import homeassistant.util.color as color_util @@ -269,14 +270,15 @@ async def async_turn_on(self, **kwargs): def _turn_on(self, **kwargs): """Turn the specified or all lights on.""" self._bulb.turnOn() - + hs_color = kwargs.get(ATTR_HS_COLOR) brightness = kwargs.get(ATTR_BRIGHTNESS) effect = kwargs.get(ATTR_EFFECT) white = kwargs.get(ATTR_WHITE_VALUE) color_temp = kwargs.get(ATTR_COLOR_TEMP) - if all(item is None for item in [hs_color, brightness, effect, white, color_temp]): + if all(item is None for item in + [hs_color, brightness, effect, white, color_temp]): return # handle W only mode (use brightness instead of white value) @@ -302,7 +304,7 @@ def _turn_on(self, **kwargs): elif effect in EFFECT_MAP: self._bulb.setPresetPattern(EFFECT_MAP[effect], 50) return - + # handle special modes if color_temp is not None: if brightness is None: @@ -312,7 +314,8 @@ def _turn_on(self, **kwargs): elif color_temp == COLOR_TEMP_COOL_WHITE: self._bulb.setRgbw(w2=brightness) else: - self._bulb.setRgbw(*color_util.color_temperature_to_rgb(color_temp)) + self._bulb.setRgbw( + *color_util.color_temperature_to_rgb(color_temp)) return # Preserve current brightness on color/white level change From bfd89c206faf6249f3ef758e5be6e3841146620c Mon Sep 17 00:00:00 2001 From: Daniyar Yeralin Date: Wed, 31 Jul 2019 10:54:09 -0400 Subject: [PATCH 3/3] Remove extra whitespace for pylint --- homeassistant/components/flux_led/light.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/flux_led/light.py b/homeassistant/components/flux_led/light.py index c5f6c3f967e194..02bc20ccb1da25 100644 --- a/homeassistant/components/flux_led/light.py +++ b/homeassistant/components/flux_led/light.py @@ -278,7 +278,7 @@ def _turn_on(self, **kwargs): color_temp = kwargs.get(ATTR_COLOR_TEMP) if all(item is None for item in - [hs_color, brightness, effect, white, color_temp]): + [hs_color, brightness, effect, white, color_temp]): return # handle W only mode (use brightness instead of white value)