mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix light color mode in govee_light_local (#108762)
This commit is contained in:
parent
f1392f8519
commit
7ef3ed6107
@ -13,6 +13,7 @@ from homeassistant.components.light import (
|
|||||||
ATTR_RGB_COLOR,
|
ATTR_RGB_COLOR,
|
||||||
ColorMode,
|
ColorMode,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
|
filter_supported_color_modes,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
@ -52,6 +53,8 @@ class GoveeLight(CoordinatorEntity[GoveeLocalApiCoordinator], LightEntity):
|
|||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
_attr_supported_color_modes: set[ColorMode]
|
||||||
|
_fixed_color_mode: ColorMode | None = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -67,7 +70,7 @@ class GoveeLight(CoordinatorEntity[GoveeLocalApiCoordinator], LightEntity):
|
|||||||
self._attr_unique_id = device.fingerprint
|
self._attr_unique_id = device.fingerprint
|
||||||
|
|
||||||
capabilities = device.capabilities
|
capabilities = device.capabilities
|
||||||
color_modes = set()
|
color_modes = {ColorMode.ONOFF}
|
||||||
if capabilities:
|
if capabilities:
|
||||||
if GoveeLightCapability.COLOR_RGB in capabilities:
|
if GoveeLightCapability.COLOR_RGB in capabilities:
|
||||||
color_modes.add(ColorMode.RGB)
|
color_modes.add(ColorMode.RGB)
|
||||||
@ -77,10 +80,11 @@ class GoveeLight(CoordinatorEntity[GoveeLocalApiCoordinator], LightEntity):
|
|||||||
self._attr_min_color_temp_kelvin = 2000
|
self._attr_min_color_temp_kelvin = 2000
|
||||||
if GoveeLightCapability.BRIGHTNESS in capabilities:
|
if GoveeLightCapability.BRIGHTNESS in capabilities:
|
||||||
color_modes.add(ColorMode.BRIGHTNESS)
|
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(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={
|
identifiers={
|
||||||
@ -116,21 +120,19 @@ class GoveeLight(CoordinatorEntity[GoveeLocalApiCoordinator], LightEntity):
|
|||||||
@property
|
@property
|
||||||
def color_mode(self) -> ColorMode | str | None:
|
def color_mode(self) -> ColorMode | str | None:
|
||||||
"""Return the color mode."""
|
"""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 (
|
if (
|
||||||
self._device.temperature_color is not None
|
self._device.temperature_color is not None
|
||||||
and self._device.temperature_color > 0
|
and self._device.temperature_color > 0
|
||||||
):
|
):
|
||||||
return ColorMode.COLOR_TEMP
|
return ColorMode.COLOR_TEMP
|
||||||
if self._device.rgb_color is not None and any(self._device.rgb_color):
|
|
||||||
return ColorMode.RGB
|
return ColorMode.RGB
|
||||||
|
|
||||||
if (
|
|
||||||
self._attr_supported_color_modes
|
|
||||||
and ColorMode.BRIGHTNESS in self._attr_supported_color_modes
|
|
||||||
):
|
|
||||||
return ColorMode.BRIGHTNESS
|
|
||||||
return ColorMode.ONOFF
|
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the device on."""
|
"""Turn the device on."""
|
||||||
if not self.is_on or not kwargs:
|
if not self.is_on or not kwargs:
|
||||||
|
@ -46,9 +46,7 @@ async def test_light_known_device(
|
|||||||
assert light is not None
|
assert light is not None
|
||||||
|
|
||||||
color_modes = light.attributes[ATTR_SUPPORTED_COLOR_MODES]
|
color_modes = light.attributes[ATTR_SUPPORTED_COLOR_MODES]
|
||||||
assert ColorMode.RGB in color_modes
|
assert set(color_modes) == {ColorMode.COLOR_TEMP, ColorMode.RGB}
|
||||||
assert ColorMode.BRIGHTNESS in color_modes
|
|
||||||
assert ColorMode.COLOR_TEMP in color_modes
|
|
||||||
|
|
||||||
# Remove
|
# Remove
|
||||||
assert await hass.config_entries.async_remove(entry.entry_id)
|
assert await hass.config_entries.async_remove(entry.entry_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user