mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Migrate matter lights to use Kelvin (#132685)
This commit is contained in:
parent
879e082b54
commit
020db5f822
@ -9,7 +9,7 @@ from matter_server.client.models import device_types
|
|||||||
|
|
||||||
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,
|
||||||
ATTR_TRANSITION,
|
ATTR_TRANSITION,
|
||||||
ATTR_XY_COLOR,
|
ATTR_XY_COLOR,
|
||||||
@ -23,6 +23,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.util import color as color_util
|
||||||
|
|
||||||
from .const import LOGGER
|
from .const import LOGGER
|
||||||
from .entity import MatterEntity
|
from .entity import MatterEntity
|
||||||
@ -131,12 +132,16 @@ class MatterLight(MatterEntity, LightEntity):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _set_color_temp(self, color_temp: int, transition: float = 0.0) -> None:
|
async def _set_color_temp(
|
||||||
|
self, color_temp_kelvin: int, transition: float = 0.0
|
||||||
|
) -> None:
|
||||||
"""Set color temperature."""
|
"""Set color temperature."""
|
||||||
|
color_temp_mired = color_util.color_temperature_kelvin_to_mired(
|
||||||
|
color_temp_kelvin
|
||||||
|
)
|
||||||
await self.send_device_command(
|
await self.send_device_command(
|
||||||
clusters.ColorControl.Commands.MoveToColorTemperature(
|
clusters.ColorControl.Commands.MoveToColorTemperature(
|
||||||
colorTemperatureMireds=color_temp,
|
colorTemperatureMireds=color_temp_mired,
|
||||||
# transition in matter is measured in tenths of a second
|
# transition in matter is measured in tenths of a second
|
||||||
transitionTime=int(transition * 10),
|
transitionTime=int(transition * 10),
|
||||||
# allow setting the color while the light is off,
|
# allow setting the color while the light is off,
|
||||||
@ -286,7 +291,7 @@ class MatterLight(MatterEntity, LightEntity):
|
|||||||
|
|
||||||
hs_color = kwargs.get(ATTR_HS_COLOR)
|
hs_color = kwargs.get(ATTR_HS_COLOR)
|
||||||
xy_color = kwargs.get(ATTR_XY_COLOR)
|
xy_color = kwargs.get(ATTR_XY_COLOR)
|
||||||
color_temp = kwargs.get(ATTR_COLOR_TEMP)
|
color_temp_kelvin = kwargs.get(ATTR_COLOR_TEMP_KELVIN)
|
||||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||||
transition = kwargs.get(ATTR_TRANSITION, 0)
|
transition = kwargs.get(ATTR_TRANSITION, 0)
|
||||||
if self._transitions_disabled:
|
if self._transitions_disabled:
|
||||||
@ -298,10 +303,10 @@ class MatterLight(MatterEntity, LightEntity):
|
|||||||
elif xy_color is not None and ColorMode.XY in self.supported_color_modes:
|
elif xy_color is not None and ColorMode.XY in self.supported_color_modes:
|
||||||
await self._set_xy_color(xy_color, transition)
|
await self._set_xy_color(xy_color, transition)
|
||||||
elif (
|
elif (
|
||||||
color_temp is not None
|
color_temp_kelvin is not None
|
||||||
and ColorMode.COLOR_TEMP in self.supported_color_modes
|
and ColorMode.COLOR_TEMP in self.supported_color_modes
|
||||||
):
|
):
|
||||||
await self._set_color_temp(color_temp, transition)
|
await self._set_color_temp(color_temp_kelvin, transition)
|
||||||
|
|
||||||
if brightness is not None and self._supports_brightness:
|
if brightness is not None and self._supports_brightness:
|
||||||
await self._set_brightness(brightness, transition)
|
await self._set_brightness(brightness, transition)
|
||||||
@ -368,12 +373,16 @@ class MatterLight(MatterEntity, LightEntity):
|
|||||||
clusters.ColorControl.Attributes.ColorTempPhysicalMinMireds
|
clusters.ColorControl.Attributes.ColorTempPhysicalMinMireds
|
||||||
)
|
)
|
||||||
if min_mireds > 0:
|
if min_mireds > 0:
|
||||||
self._attr_min_mireds = min_mireds
|
self._attr_max_color_temp_kelvin = (
|
||||||
|
color_util.color_temperature_mired_to_kelvin(min_mireds)
|
||||||
|
)
|
||||||
max_mireds = self.get_matter_attribute_value(
|
max_mireds = self.get_matter_attribute_value(
|
||||||
clusters.ColorControl.Attributes.ColorTempPhysicalMaxMireds
|
clusters.ColorControl.Attributes.ColorTempPhysicalMaxMireds
|
||||||
)
|
)
|
||||||
if max_mireds > 0:
|
if max_mireds > 0:
|
||||||
self._attr_max_mireds = max_mireds
|
self._attr_min_color_temp_kelvin = (
|
||||||
|
color_util.color_temperature_mired_to_kelvin(max_mireds)
|
||||||
|
)
|
||||||
|
|
||||||
supported_color_modes = filter_supported_color_modes(supported_color_modes)
|
supported_color_modes = filter_supported_color_modes(supported_color_modes)
|
||||||
self._attr_supported_color_modes = supported_color_modes
|
self._attr_supported_color_modes = supported_color_modes
|
||||||
@ -399,8 +408,13 @@ class MatterLight(MatterEntity, LightEntity):
|
|||||||
if self._supports_brightness:
|
if self._supports_brightness:
|
||||||
self._attr_brightness = self._get_brightness()
|
self._attr_brightness = self._get_brightness()
|
||||||
|
|
||||||
if self._supports_color_temperature:
|
if (
|
||||||
self._attr_color_temp = self._get_color_temperature()
|
self._supports_color_temperature
|
||||||
|
and (color_temperature := self._get_color_temperature()) > 0
|
||||||
|
):
|
||||||
|
self._attr_color_temp_kelvin = color_util.color_temperature_mired_to_kelvin(
|
||||||
|
color_temperature
|
||||||
|
)
|
||||||
|
|
||||||
if self._supports_color:
|
if self._supports_color:
|
||||||
self._attr_color_mode = color_mode = self._get_color_mode()
|
self._attr_color_mode = color_mode = self._get_color_mode()
|
||||||
@ -414,7 +428,7 @@ class MatterLight(MatterEntity, LightEntity):
|
|||||||
and color_mode == ColorMode.XY
|
and color_mode == ColorMode.XY
|
||||||
):
|
):
|
||||||
self._attr_xy_color = self._get_xy_color()
|
self._attr_xy_color = self._get_xy_color()
|
||||||
elif self._attr_color_temp is not None:
|
elif self._attr_color_temp_kelvin is not None:
|
||||||
self._attr_color_mode = ColorMode.COLOR_TEMP
|
self._attr_color_mode = ColorMode.COLOR_TEMP
|
||||||
elif self._attr_brightness is not None:
|
elif self._attr_brightness is not None:
|
||||||
self._attr_color_mode = ColorMode.BRIGHTNESS
|
self._attr_color_mode = ColorMode.BRIGHTNESS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user