Migrate elgato lights to use Kelvin (#132789)

This commit is contained in:
epenet 2024-12-10 08:15:47 +01:00 committed by GitHub
parent 5062a7fec8
commit e83a50b88d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 25 deletions

View File

@ -8,7 +8,7 @@ from elgato import ElgatoError
from homeassistant.components.light import ( from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP, ATTR_COLOR_TEMP_KELVIN,
ATTR_HS_COLOR, ATTR_HS_COLOR,
ColorMode, ColorMode,
LightEntity, LightEntity,
@ -19,6 +19,7 @@ from homeassistant.helpers.entity_platform import (
AddEntitiesCallback, AddEntitiesCallback,
async_get_current_platform, async_get_current_platform,
) )
from homeassistant.util import color as color_util
from . import ElgatorConfigEntry from . import ElgatorConfigEntry
from .const import SERVICE_IDENTIFY from .const import SERVICE_IDENTIFY
@ -49,8 +50,8 @@ class ElgatoLight(ElgatoEntity, LightEntity):
"""Defines an Elgato Light.""" """Defines an Elgato Light."""
_attr_name = None _attr_name = None
_attr_min_mireds = 143 _attr_min_color_temp_kelvin = 2900 # 344 Mireds
_attr_max_mireds = 344 _attr_max_color_temp_kelvin = 7000 # 143 Mireds
def __init__(self, coordinator: ElgatoDataUpdateCoordinator) -> None: def __init__(self, coordinator: ElgatoDataUpdateCoordinator) -> None:
"""Initialize Elgato Light.""" """Initialize Elgato Light."""
@ -69,8 +70,8 @@ class ElgatoLight(ElgatoEntity, LightEntity):
or self.coordinator.data.state.hue is not None or self.coordinator.data.state.hue is not None
): ):
self._attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS} self._attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS}
self._attr_min_mireds = 153 self._attr_min_color_temp_kelvin = 3500 # 285 Mireds
self._attr_max_mireds = 285 self._attr_max_color_temp_kelvin = 6500 # 153 Mireds
@property @property
def brightness(self) -> int | None: def brightness(self) -> int | None:
@ -78,9 +79,11 @@ class ElgatoLight(ElgatoEntity, LightEntity):
return round((self.coordinator.data.state.brightness * 255) / 100) return round((self.coordinator.data.state.brightness * 255) / 100)
@property @property
def color_temp(self) -> int | None: def color_temp_kelvin(self) -> int | None:
"""Return the CT color value in mireds.""" """Return the color temperature value in Kelvin."""
return self.coordinator.data.state.temperature if (mired_temperature := self.coordinator.data.state.temperature) is None:
return None
return color_util.color_temperature_mired_to_kelvin(mired_temperature)
@property @property
def color_mode(self) -> str | None: def color_mode(self) -> str | None:
@ -116,7 +119,7 @@ class ElgatoLight(ElgatoEntity, LightEntity):
async def async_turn_on(self, **kwargs: Any) -> None: async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the light.""" """Turn on the light."""
temperature = kwargs.get(ATTR_COLOR_TEMP) temperature_kelvin = kwargs.get(ATTR_COLOR_TEMP_KELVIN)
hue = None hue = None
saturation = None saturation = None
@ -133,12 +136,18 @@ class ElgatoLight(ElgatoEntity, LightEntity):
if ( if (
brightness brightness
and ATTR_HS_COLOR not in kwargs and ATTR_HS_COLOR not in kwargs
and ATTR_COLOR_TEMP not in kwargs and ATTR_COLOR_TEMP_KELVIN not in kwargs
and self.supported_color_modes and self.supported_color_modes
and ColorMode.HS in self.supported_color_modes and ColorMode.HS in self.supported_color_modes
and self.color_mode == ColorMode.COLOR_TEMP and self.color_mode == ColorMode.COLOR_TEMP
): ):
temperature = self.color_temp temperature_kelvin = self.color_temp_kelvin
temperature = (
None
if temperature_kelvin is None
else color_util.color_temperature_kelvin_to_mired(temperature_kelvin)
)
try: try:
await self.coordinator.client.light( await self.coordinator.client.light(

View File

@ -11,10 +11,10 @@
27.316, 27.316,
47.743, 47.743,
), ),
'max_color_temp_kelvin': 6993, 'max_color_temp_kelvin': 7000,
'max_mireds': 344, 'max_mireds': 344,
'min_color_temp_kelvin': 2906, 'min_color_temp_kelvin': 2900,
'min_mireds': 143, 'min_mireds': 142,
'rgb_color': tuple( 'rgb_color': tuple(
255, 255,
189, 189,
@ -43,10 +43,10 @@
}), }),
'area_id': None, 'area_id': None,
'capabilities': dict({ 'capabilities': dict({
'max_color_temp_kelvin': 6993, 'max_color_temp_kelvin': 7000,
'max_mireds': 344, 'max_mireds': 344,
'min_color_temp_kelvin': 2906, 'min_color_temp_kelvin': 2900,
'min_mireds': 143, 'min_mireds': 142,
'supported_color_modes': list([ 'supported_color_modes': list([
<ColorMode.COLOR_TEMP: 'color_temp'>, <ColorMode.COLOR_TEMP: 'color_temp'>,
]), ]),
@ -126,9 +126,9 @@
27.316, 27.316,
47.743, 47.743,
), ),
'max_color_temp_kelvin': 6535, 'max_color_temp_kelvin': 6500,
'max_mireds': 285, 'max_mireds': 285,
'min_color_temp_kelvin': 3508, 'min_color_temp_kelvin': 3500,
'min_mireds': 153, 'min_mireds': 153,
'rgb_color': tuple( 'rgb_color': tuple(
255, 255,
@ -159,9 +159,9 @@
}), }),
'area_id': None, 'area_id': None,
'capabilities': dict({ 'capabilities': dict({
'max_color_temp_kelvin': 6535, 'max_color_temp_kelvin': 6500,
'max_mireds': 285, 'max_mireds': 285,
'min_color_temp_kelvin': 3508, 'min_color_temp_kelvin': 3500,
'min_mireds': 153, 'min_mireds': 153,
'supported_color_modes': list([ 'supported_color_modes': list([
<ColorMode.COLOR_TEMP: 'color_temp'>, <ColorMode.COLOR_TEMP: 'color_temp'>,
@ -243,9 +243,9 @@
358.0, 358.0,
6.0, 6.0,
), ),
'max_color_temp_kelvin': 6535, 'max_color_temp_kelvin': 6500,
'max_mireds': 285, 'max_mireds': 285,
'min_color_temp_kelvin': 3508, 'min_color_temp_kelvin': 3500,
'min_mireds': 153, 'min_mireds': 153,
'rgb_color': tuple( 'rgb_color': tuple(
255, 255,
@ -276,9 +276,9 @@
}), }),
'area_id': None, 'area_id': None,
'capabilities': dict({ 'capabilities': dict({
'max_color_temp_kelvin': 6535, 'max_color_temp_kelvin': 6500,
'max_mireds': 285, 'max_mireds': 285,
'min_color_temp_kelvin': 3508, 'min_color_temp_kelvin': 3500,
'min_mireds': 153, 'min_mireds': 153,
'supported_color_modes': list([ 'supported_color_modes': list([
<ColorMode.COLOR_TEMP: 'color_temp'>, <ColorMode.COLOR_TEMP: 'color_temp'>,