Handle color temp to RGBWW conversion (#61473)

Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
J. Nick Koston 2021-12-16 05:39:33 -06:00 committed by GitHub
parent 12671b370e
commit 94ae6ac2b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 140 additions and 8 deletions

View file

@ -382,14 +382,22 @@ async def async_setup(hass, config): # noqa: C901
params[ATTR_WHITE_VALUE] = rgbw_color[3]
# If a color temperature is specified, emulate it if not supported by the light
if (
ATTR_COLOR_TEMP in params
and COLOR_MODE_COLOR_TEMP not in legacy_supported_color_modes
):
color_temp = params.pop(ATTR_COLOR_TEMP)
if color_supported(legacy_supported_color_modes):
temp_k = color_util.color_temperature_mired_to_kelvin(color_temp)
params[ATTR_HS_COLOR] = color_util.color_temperature_to_hs(temp_k)
if ATTR_COLOR_TEMP in params:
if (
supported_color_modes
and COLOR_MODE_COLOR_TEMP not in supported_color_modes
and COLOR_MODE_RGBWW in supported_color_modes
):
color_temp = params.pop(ATTR_COLOR_TEMP)
brightness = params.get(ATTR_BRIGHTNESS, light.brightness)
params[ATTR_RGBWW_COLOR] = color_util.color_temperature_to_rgbww(
color_temp, brightness, light.min_mireds, light.max_mireds
)
elif COLOR_MODE_COLOR_TEMP not in legacy_supported_color_modes:
color_temp = params.pop(ATTR_COLOR_TEMP)
if color_supported(legacy_supported_color_modes):
temp_k = color_util.color_temperature_mired_to_kelvin(color_temp)
params[ATTR_HS_COLOR] = color_util.color_temperature_to_hs(temp_k)
# If a color is specified, convert to the color space supported by the light
# Backwards compatibility: Fall back to hs color if light.supported_color_modes