mirror of
https://github.com/home-assistant/core.git
synced 2025-05-05 22:49:17 +00:00
Migrate tasmota lights to use Kelvin (#132798)
This commit is contained in:
parent
2bb05296b8
commit
7ef3e92e2d
@ -18,7 +18,7 @@ from hatasmota.models import DiscoveryHashType
|
|||||||
from homeassistant.components import light
|
from homeassistant.components import light
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
ATTR_COLOR_TEMP,
|
ATTR_COLOR_TEMP_KELVIN,
|
||||||
ATTR_EFFECT,
|
ATTR_EFFECT,
|
||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
ATTR_TRANSITION,
|
ATTR_TRANSITION,
|
||||||
@ -32,6 +32,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
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 DATA_REMOVE_DISCOVER_COMPONENT
|
from .const import DATA_REMOVE_DISCOVER_COMPONENT
|
||||||
from .discovery import TASMOTA_DISCOVERY_ENTITY_NEW
|
from .discovery import TASMOTA_DISCOVERY_ENTITY_NEW
|
||||||
@ -199,19 +200,27 @@ class TasmotaLight(
|
|||||||
return self._color_mode
|
return self._color_mode
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color_temp(self) -> int | None:
|
def color_temp_kelvin(self) -> int | None:
|
||||||
"""Return the color temperature in mired."""
|
"""Return the color temperature value in Kelvin."""
|
||||||
return self._color_temp
|
return (
|
||||||
|
color_util.color_temperature_mired_to_kelvin(self._color_temp)
|
||||||
|
if self._color_temp
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def min_mireds(self) -> int:
|
def max_color_temp_kelvin(self) -> int:
|
||||||
"""Return the coldest color_temp that this light supports."""
|
"""Return the coldest color_temp_kelvin that this light supports."""
|
||||||
return self._tasmota_entity.min_mireds
|
return color_util.color_temperature_mired_to_kelvin(
|
||||||
|
self._tasmota_entity.min_mireds
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def max_mireds(self) -> int:
|
def min_color_temp_kelvin(self) -> int:
|
||||||
"""Return the warmest color_temp that this light supports."""
|
"""Return the warmest color_temp_kelvin that this light supports."""
|
||||||
return self._tasmota_entity.max_mireds
|
return color_util.color_temperature_mired_to_kelvin(
|
||||||
|
self._tasmota_entity.max_mireds
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def effect(self) -> str | None:
|
def effect(self) -> str | None:
|
||||||
@ -255,8 +264,13 @@ class TasmotaLight(
|
|||||||
if ATTR_BRIGHTNESS in kwargs and brightness_supported(supported_color_modes):
|
if ATTR_BRIGHTNESS in kwargs and brightness_supported(supported_color_modes):
|
||||||
attributes["brightness"] = scale_brightness(kwargs[ATTR_BRIGHTNESS])
|
attributes["brightness"] = scale_brightness(kwargs[ATTR_BRIGHTNESS])
|
||||||
|
|
||||||
if ATTR_COLOR_TEMP in kwargs and ColorMode.COLOR_TEMP in supported_color_modes:
|
if (
|
||||||
attributes["color_temp"] = int(kwargs[ATTR_COLOR_TEMP])
|
ATTR_COLOR_TEMP_KELVIN in kwargs
|
||||||
|
and ColorMode.COLOR_TEMP in supported_color_modes
|
||||||
|
):
|
||||||
|
attributes["color_temp"] = color_util.color_temperature_kelvin_to_mired(
|
||||||
|
kwargs[ATTR_COLOR_TEMP_KELVIN]
|
||||||
|
)
|
||||||
|
|
||||||
if ATTR_EFFECT in kwargs:
|
if ATTR_EFFECT in kwargs:
|
||||||
attributes["effect"] = kwargs[ATTR_EFFECT]
|
attributes["effect"] = kwargs[ATTR_EFFECT]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user