Fix ESPHome color modes for older firmwares (#108870)

pull/108668/head
J. Nick Koston 2024-01-25 10:18:53 -10:00 committed by GitHub
parent 2b799830db
commit 3447e7fddb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -402,12 +402,24 @@ class EsphomeLight(EsphomeEntity[LightInfo, LightState], LightEntity):
self._attr_supported_features = flags
supported = set(map(_color_mode_to_ha, self._native_supported_color_modes))
# If we don't know the supported color modes, ESPHome lights
# are always at least ONOFF so we can safely discard UNKNOWN
supported.discard(ColorMode.UNKNOWN)
if ColorMode.ONOFF in supported and len(supported) > 1:
supported.remove(ColorMode.ONOFF)
if ColorMode.BRIGHTNESS in supported and len(supported) > 1:
supported.remove(ColorMode.BRIGHTNESS)
if ColorMode.WHITE in supported and len(supported) == 1:
supported.remove(ColorMode.WHITE)
# If we don't know the supported color modes, its a very old
# legacy device, and since ESPHome lights are always at least ONOFF
# we can safely assume that it supports ONOFF
if not supported:
supported.add(ColorMode.ONOFF)
self._attr_supported_color_modes = supported
self._attr_effect_list = static_info.effects
self._attr_min_mireds = round(static_info.min_mireds)

View File

@ -1865,7 +1865,7 @@ async def test_light_no_color_modes(
state = hass.states.get("light.test_mylight")
assert state is not None
assert state.state == STATE_ON
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.UNKNOWN]
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.ONOFF]
await hass.services.async_call(
LIGHT_DOMAIN,