Move the Elgato color temperature range out of the light entity (#180719)

This commit is contained in:
Franck Nijhof
2026-08-30 11:57:24 +02:00
committed by GitHub
parent 16e84ddaf4
commit 9b368640e4
2 changed files with 30 additions and 15 deletions
@@ -8,8 +8,31 @@ from elgato import ElgatoConnectionError, ElgatoError
from homeassistant.exceptions import HomeAssistantError
from .const import DOMAIN
from .coordinator import ElgatoData
from .entity import ElgatoEntity
# Elgato lights that can do color reach less far at either end.
COLOR_TEMPERATURE_RANGE = (2900, 6993) # 344 - 143 mireds
COLOR_TEMPERATURE_RANGE_COLOR = (3500, 6500) # 285 - 153 mireds
COLOR_CAPABLE_PRODUCTS = ("Elgato Light Strip", "Elgato Light Strip Pro")
def supports_color(data: ElgatoData) -> bool:
"""Return if an Elgato Light does more than white."""
return bool(
data.info.product_name in COLOR_CAPABLE_PRODUCTS
or data.settings.power_on_hue
or data.state.hue is not None
)
def color_temperature_range(data: ElgatoData) -> tuple[int, int]:
"""Return the color temperature range in Kelvin a device supports."""
if supports_color(data):
return COLOR_TEMPERATURE_RANGE_COLOR
return COLOR_TEMPERATURE_RANGE
def elgato_exception_handler[_ElgatoEntityT: ElgatoEntity, **_P](
func: Callable[Concatenate[_ElgatoEntityT, _P], Coroutine[Any, Any, Any]],
+7 -15
View File
@@ -15,7 +15,7 @@ from homeassistant.util import color as color_util
from .coordinator import ElgatoConfigEntry, ElgatoDataUpdateCoordinator
from .entity import ElgatoEntity
from .helpers import elgato_exception_handler
from .helpers import color_temperature_range, elgato_exception_handler, supports_color
PARALLEL_UPDATES = 1
@@ -34,8 +34,6 @@ class ElgatoLight(ElgatoEntity, LightEntity):
"""Defines an Elgato Light."""
_attr_name = None
_attr_min_color_temp_kelvin = 2900 # 344 Mireds
_attr_max_color_temp_kelvin = 6993 # 143 Mireds
def __init__(self, coordinator: ElgatoDataUpdateCoordinator) -> None:
"""Initialize Elgato Light."""
@@ -43,19 +41,13 @@ class ElgatoLight(ElgatoEntity, LightEntity):
self._attr_supported_color_modes = {ColorMode.COLOR_TEMP}
self._attr_unique_id = coordinator.data.info.serial_number
# Elgato Light supporting color, have a different temperature range
if (
self.coordinator.data.info.product_name
in (
"Elgato Light Strip",
"Elgato Light Strip Pro",
)
or self.coordinator.data.settings.power_on_hue
or self.coordinator.data.state.hue is not None
):
if supports_color(coordinator.data):
self._attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS}
self._attr_min_color_temp_kelvin = 3500 # 285 Mireds
self._attr_max_color_temp_kelvin = 6500 # 153 Mireds
(
self._attr_min_color_temp_kelvin,
self._attr_max_color_temp_kelvin,
) = color_temperature_range(coordinator.data)
@property
@override