Fix ESPHome color modes for older firmwares (#108870)
This commit is contained in:
parent
2b799830db
commit
3447e7fddb
2 changed files with 13 additions and 1 deletions
|
@ -402,12 +402,24 @@ class EsphomeLight(EsphomeEntity[LightInfo, LightState], LightEntity):
|
||||||
self._attr_supported_features = flags
|
self._attr_supported_features = flags
|
||||||
|
|
||||||
supported = set(map(_color_mode_to_ha, self._native_supported_color_modes))
|
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:
|
if ColorMode.ONOFF in supported and len(supported) > 1:
|
||||||
supported.remove(ColorMode.ONOFF)
|
supported.remove(ColorMode.ONOFF)
|
||||||
if ColorMode.BRIGHTNESS in supported and len(supported) > 1:
|
if ColorMode.BRIGHTNESS in supported and len(supported) > 1:
|
||||||
supported.remove(ColorMode.BRIGHTNESS)
|
supported.remove(ColorMode.BRIGHTNESS)
|
||||||
if ColorMode.WHITE in supported and len(supported) == 1:
|
if ColorMode.WHITE in supported and len(supported) == 1:
|
||||||
supported.remove(ColorMode.WHITE)
|
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_supported_color_modes = supported
|
||||||
self._attr_effect_list = static_info.effects
|
self._attr_effect_list = static_info.effects
|
||||||
self._attr_min_mireds = round(static_info.min_mireds)
|
self._attr_min_mireds = round(static_info.min_mireds)
|
||||||
|
|
|
@ -1865,7 +1865,7 @@ async def test_light_no_color_modes(
|
||||||
state = hass.states.get("light.test_mylight")
|
state = hass.states.get("light.test_mylight")
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == STATE_ON
|
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(
|
await hass.services.async_call(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue