diff --git a/homeassistant/components/govee_light_local/light.py b/homeassistant/components/govee_light_local/light.py index fec0ff5a898..836f48d2ea9 100644 --- a/homeassistant/components/govee_light_local/light.py +++ b/homeassistant/components/govee_light_local/light.py @@ -13,6 +13,7 @@ from homeassistant.components.light import ( ATTR_RGB_COLOR, ColorMode, LightEntity, + filter_supported_color_modes, ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback @@ -52,6 +53,8 @@ class GoveeLight(CoordinatorEntity[GoveeLocalApiCoordinator], LightEntity): _attr_has_entity_name = True _attr_name = None + _attr_supported_color_modes: set[ColorMode] + _fixed_color_mode: ColorMode | None = None def __init__( self, @@ -67,7 +70,7 @@ class GoveeLight(CoordinatorEntity[GoveeLocalApiCoordinator], LightEntity): self._attr_unique_id = device.fingerprint capabilities = device.capabilities - color_modes = set() + color_modes = {ColorMode.ONOFF} if capabilities: if GoveeLightCapability.COLOR_RGB in capabilities: color_modes.add(ColorMode.RGB) @@ -77,10 +80,11 @@ class GoveeLight(CoordinatorEntity[GoveeLocalApiCoordinator], LightEntity): self._attr_min_color_temp_kelvin = 2000 if GoveeLightCapability.BRIGHTNESS in capabilities: color_modes.add(ColorMode.BRIGHTNESS) - else: - color_modes.add(ColorMode.ONOFF) - self._attr_supported_color_modes = color_modes + self._attr_supported_color_modes = filter_supported_color_modes(color_modes) + if len(self._attr_supported_color_modes) == 1: + # If the light supports only a single color mode, set it now + self._fixed_color_mode = next(iter(self._attr_supported_color_modes)) self._attr_device_info = DeviceInfo( identifiers={ @@ -116,20 +120,18 @@ class GoveeLight(CoordinatorEntity[GoveeLocalApiCoordinator], LightEntity): @property def color_mode(self) -> ColorMode | str | None: """Return the color mode.""" + if self._fixed_color_mode: + # The light supports only a single color mode, return it + return self._fixed_color_mode + + # The light supports both color temperature and RGB, determine which + # mode the light is in if ( self._device.temperature_color is not None and self._device.temperature_color > 0 ): return ColorMode.COLOR_TEMP - if self._device.rgb_color is not None and any(self._device.rgb_color): - return ColorMode.RGB - - if ( - self._attr_supported_color_modes - and ColorMode.BRIGHTNESS in self._attr_supported_color_modes - ): - return ColorMode.BRIGHTNESS - return ColorMode.ONOFF + return ColorMode.RGB async def async_turn_on(self, **kwargs: Any) -> None: """Turn the device on.""" diff --git a/tests/components/govee_light_local/test_light.py b/tests/components/govee_light_local/test_light.py index 63ffd7179a2..1e211610d7a 100644 --- a/tests/components/govee_light_local/test_light.py +++ b/tests/components/govee_light_local/test_light.py @@ -46,9 +46,7 @@ async def test_light_known_device( assert light is not None color_modes = light.attributes[ATTR_SUPPORTED_COLOR_MODES] - assert ColorMode.RGB in color_modes - assert ColorMode.BRIGHTNESS in color_modes - assert ColorMode.COLOR_TEMP in color_modes + assert set(color_modes) == {ColorMode.COLOR_TEMP, ColorMode.RGB} # Remove assert await hass.config_entries.async_remove(entry.entry_id)