From ffb8872f959d4e9b935c3dcded7b33dbd99b7d4f Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Wed, 26 Apr 2017 17:21:14 +0200 Subject: [PATCH] LIFX: use white light when setting a specific temperature (#7256) * Default to white when setting LIFX temperature Changing the temperature of a saturated color is possible but not very interesting. So assume that a change of the temperature implies setting the color to white, unless a different color is actually specified. This makes the frontend temperature picker much more useful because it can now be used to get away from a colored light. * Default to a neutral white temperature when setting LIFX colors This means that setting a particular color will always give the same output, no matter what the temperature was previously at. * Find brightness after colors Now the color_temp logic will not see a changed color when setting temperature+brightness and thus we will actually get a white light in this situation. The XY conversion can then not use brightness as input. This is not an issue because XY only affects hue and saturation, not brightness. So we can just use an arbitrary value as brightness input. * Add a simple comment to a complex conditional --- .../components/light/lifx/__init__.py | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/light/lifx/__init__.py b/homeassistant/components/light/lifx/__init__.py index 552e1d8f77f..c43b901e910 100644 --- a/homeassistant/components/light/lifx/__init__.py +++ b/homeassistant/components/light/lifx/__init__.py @@ -353,27 +353,33 @@ class LIFXLight(Light): saturation = self._sat brightness = self._bri + if ATTR_XY_COLOR in kwargs: + hue, saturation, _ = \ + color_util.color_xy_brightness_to_hsv( + *kwargs[ATTR_XY_COLOR], + ibrightness=255) + saturation = saturation * (BYTE_MAX + 1) + changed_color = True + + # When color or temperature is set, use a default value for the other + if ATTR_COLOR_TEMP in kwargs: + kelvin = int(color_temperature_mired_to_kelvin( + kwargs[ATTR_COLOR_TEMP])) + if not changed_color: + saturation = 0 + changed_color = True + else: + if changed_color: + kelvin = 3500 + else: + kelvin = self._kel + if ATTR_BRIGHTNESS in kwargs: brightness = kwargs[ATTR_BRIGHTNESS] * (BYTE_MAX + 1) changed_color = True else: brightness = self._bri - if ATTR_XY_COLOR in kwargs: - hue, saturation, _ = \ - color_util.color_xy_brightness_to_hsv( - *kwargs[ATTR_XY_COLOR], - ibrightness=(brightness // (BYTE_MAX + 1))) - saturation = saturation * (BYTE_MAX + 1) - changed_color = True - - if ATTR_COLOR_TEMP in kwargs: - kelvin = int(color_temperature_mired_to_kelvin( - kwargs[ATTR_COLOR_TEMP])) - changed_color = True - else: - kelvin = self._kel - return [[hue, saturation, brightness, kelvin], changed_color] def set_power(self, power):