Merge branch 'main' into add-watched-lights

This commit is contained in:
Bas Nijholt 2023-04-27 12:59:37 -07:00 committed by GitHub
commit ea73228ef8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 100 additions and 15 deletions

View file

@ -157,12 +157,13 @@ from .const import (
)
_SUPPORT_OPTS = {
"brightness": SUPPORT_BRIGHTNESS,
"color_temp": SUPPORT_COLOR_TEMP,
"color": SUPPORT_COLOR,
"transition": SUPPORT_TRANSITION,
COLOR_MODE_BRIGHTNESS: SUPPORT_BRIGHTNESS,
COLOR_MODE_COLOR_TEMP: SUPPORT_COLOR_TEMP,
CONST_COLOR: SUPPORT_COLOR,
ATTR_TRANSITION: SUPPORT_TRANSITION,
}
VALID_COLOR_MODES = {
COLOR_MODE_BRIGHTNESS: ATTR_BRIGHTNESS,
COLOR_MODE_COLOR_TEMP: ATTR_COLOR_TEMP_KELVIN,
@ -644,16 +645,18 @@ def _expand_light_groups(hass: HomeAssistant, lights: list[str]) -> list[str]:
def _supported_to_attributes(supported):
supported_attributes = {}
supports_colors = False
for mode, attr in VALID_COLOR_MODES.items():
if mode not in supported:
continue
supported_attributes[attr] = True
if (
not supports_colors
and mode != COLOR_MODE_BRIGHTNESS
and mode != COLOR_MODE_COLOR_TEMP
):
supports_colors = True
for mode in supported:
attr = VALID_COLOR_MODES.get(mode)
if attr:
supported_attributes[attr] = True
if attr in COLOR_ATTRS:
supports_colors = True
# ATTR_SUPPORTED_FEATURES only
elif mode in _SUPPORT_OPTS:
supported_attributes[mode] = True
if CONST_COLOR in supported_attributes:
supports_colors = True
supported_attributes.pop(CONST_COLOR)
return supported_attributes, supports_colors