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
This commit is contained in:
parent
d2fb4675e1
commit
ffb8872f95
1 changed files with 21 additions and 15 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Reference in a new issue