mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Migrate mired attributes to kelvin in limitlessled (#132785)
This commit is contained in:
parent
a11bf5cce1
commit
82692f9a8f
@ -38,11 +38,7 @@ import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util.color import (
|
||||
color_hs_to_RGB,
|
||||
color_temperature_kelvin_to_mired,
|
||||
color_temperature_mired_to_kelvin,
|
||||
)
|
||||
from homeassistant.util.color import color_hs_to_RGB
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -221,8 +217,8 @@ class LimitlessLEDGroup(LightEntity, RestoreEntity):
|
||||
"""Representation of a LimitessLED group."""
|
||||
|
||||
_attr_assumed_state = True
|
||||
_attr_max_mireds = 370
|
||||
_attr_min_mireds = 154
|
||||
_attr_min_color_temp_kelvin = 2700 # 370 Mireds
|
||||
_attr_max_color_temp_kelvin = 6500 # 154 Mireds
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, group: Group, config: dict[str, Any]) -> None:
|
||||
@ -265,7 +261,9 @@ class LimitlessLEDGroup(LightEntity, RestoreEntity):
|
||||
if last_state := await self.async_get_last_state():
|
||||
self._attr_is_on = last_state.state == STATE_ON
|
||||
self._attr_brightness = last_state.attributes.get("brightness")
|
||||
self._attr_color_temp = last_state.attributes.get("color_temp")
|
||||
self._attr_color_temp_kelvin = last_state.attributes.get(
|
||||
"color_temp_kelvin"
|
||||
)
|
||||
self._attr_hs_color = last_state.attributes.get("hs_color")
|
||||
|
||||
@property
|
||||
@ -334,9 +332,7 @@ class LimitlessLEDGroup(LightEntity, RestoreEntity):
|
||||
if ColorMode.HS in self.supported_color_modes:
|
||||
pipeline.white()
|
||||
self._attr_hs_color = WHITE
|
||||
self._attr_color_temp = color_temperature_kelvin_to_mired(
|
||||
kwargs[ATTR_COLOR_TEMP_KELVIN]
|
||||
)
|
||||
self._attr_color_temp_kelvin = kwargs[ATTR_COLOR_TEMP_KELVIN]
|
||||
args["temperature"] = self.limitlessled_temperature()
|
||||
|
||||
if args:
|
||||
@ -360,12 +356,9 @@ class LimitlessLEDGroup(LightEntity, RestoreEntity):
|
||||
|
||||
def limitlessled_temperature(self) -> float:
|
||||
"""Convert Home Assistant color temperature units to percentage."""
|
||||
max_kelvin = color_temperature_mired_to_kelvin(self.min_mireds)
|
||||
min_kelvin = color_temperature_mired_to_kelvin(self.max_mireds)
|
||||
width = max_kelvin - min_kelvin
|
||||
assert self.color_temp is not None
|
||||
kelvin = color_temperature_mired_to_kelvin(self.color_temp)
|
||||
temperature = (kelvin - min_kelvin) / width
|
||||
width = self.max_color_temp_kelvin - self.min_color_temp_kelvin
|
||||
assert self.color_temp_kelvin is not None
|
||||
temperature = (self.color_temp_kelvin - self.min_color_temp_kelvin) / width
|
||||
return max(0, min(1, temperature))
|
||||
|
||||
def limitlessled_brightness(self) -> float:
|
||||
|
Loading…
x
Reference in New Issue
Block a user