Introduce SUPPORT_COLOR_TEMP for flux_led component (#26692)

* Introduce SUPPORT_COLOR_TEMP for flux_led component

* Make black linter happy

* Remove duplicate SUPPORT_COLOR_TEMP

* Make linter happy
This commit is contained in:
Daniyar Yeralin 2019-10-31 19:15:20 -04:00 committed by Teemu R
parent 5c9f7484c2
commit 54361342ba

View file

@ -12,12 +12,14 @@ from homeassistant.components.light import (
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,
)
@ -43,6 +45,10 @@ MODE_RGBW = "rgbw"
# 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 modes
COLOR_TEMP_WARM_VS_COLD_WHITE_CUT_OFF = 285
# List of supported effects which aren't already declared in LIGHT
EFFECT_RED_FADE = "red_fade"
EFFECT_GREEN_FADE = "green_fade"
@ -235,7 +241,7 @@ class FluxLight(Light):
def supported_features(self):
"""Flag supported features."""
if self._mode == MODE_RGBW:
return SUPPORT_FLUX_LED | SUPPORT_WHITE_VALUE
return SUPPORT_FLUX_LED | SUPPORT_WHITE_VALUE | SUPPORT_COLOR_TEMP
if self._mode == MODE_WHITE:
return SUPPORT_BRIGHTNESS
@ -284,6 +290,17 @@ class FluxLight(Light):
brightness = kwargs.get(ATTR_BRIGHTNESS)
effect = kwargs.get(ATTR_EFFECT)
white = kwargs.get(ATTR_WHITE_VALUE)
color_temp = kwargs.get(ATTR_COLOR_TEMP)
# handle special modes
if color_temp is not None:
if brightness is None:
brightness = self.brightness
if color_temp > COLOR_TEMP_WARM_VS_COLD_WHITE_CUT_OFF:
self._bulb.setRgbw(w=brightness)
else:
self._bulb.setRgbw(w2=brightness)
return
# Show warning if effect set with rgb, brightness, or white level
if effect and (brightness or white or rgb):