mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Migrate eufy lights to use Kelvin (#132790)
This commit is contained in:
parent
17521f25b6
commit
3d1258ddc1
@ -8,7 +8,7 @@ import lakeside
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_COLOR_TEMP,
|
||||
ATTR_COLOR_TEMP_KELVIN,
|
||||
ATTR_HS_COLOR,
|
||||
ColorMode,
|
||||
LightEntity,
|
||||
@ -17,10 +17,6 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
import homeassistant.util.color as color_util
|
||||
from homeassistant.util.color import (
|
||||
color_temperature_kelvin_to_mired as kelvin_to_mired,
|
||||
color_temperature_mired_to_kelvin as mired_to_kelvin,
|
||||
)
|
||||
|
||||
EUFYHOME_MAX_KELVIN = 6500
|
||||
EUFYHOME_MIN_KELVIN = 2700
|
||||
@ -41,6 +37,9 @@ def setup_platform(
|
||||
class EufyHomeLight(LightEntity):
|
||||
"""Representation of a EufyHome light."""
|
||||
|
||||
_attr_min_color_temp_kelvin = EUFYHOME_MIN_KELVIN
|
||||
_attr_max_color_temp_kelvin = EUFYHOME_MAX_KELVIN
|
||||
|
||||
def __init__(self, device):
|
||||
"""Initialize the light."""
|
||||
|
||||
@ -96,23 +95,12 @@ class EufyHomeLight(LightEntity):
|
||||
return int(self._brightness * 255 / 100)
|
||||
|
||||
@property
|
||||
def min_mireds(self) -> int:
|
||||
"""Return minimum supported color temperature."""
|
||||
return kelvin_to_mired(EUFYHOME_MAX_KELVIN)
|
||||
|
||||
@property
|
||||
def max_mireds(self) -> int:
|
||||
"""Return maximum supported color temperature."""
|
||||
return kelvin_to_mired(EUFYHOME_MIN_KELVIN)
|
||||
|
||||
@property
|
||||
def color_temp(self):
|
||||
"""Return the color temperature of this light."""
|
||||
temp_in_k = int(
|
||||
def color_temp_kelvin(self) -> int:
|
||||
"""Return the color temperature value in Kelvin."""
|
||||
return int(
|
||||
EUFYHOME_MIN_KELVIN
|
||||
+ (self._temp * (EUFYHOME_MAX_KELVIN - EUFYHOME_MIN_KELVIN) / 100)
|
||||
)
|
||||
return kelvin_to_mired(temp_in_k)
|
||||
|
||||
@property
|
||||
def hs_color(self):
|
||||
@ -134,7 +122,7 @@ class EufyHomeLight(LightEntity):
|
||||
def turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the specified light on."""
|
||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||
colortemp = kwargs.get(ATTR_COLOR_TEMP)
|
||||
color_temp_kelvin = kwargs.get(ATTR_COLOR_TEMP_KELVIN)
|
||||
hs = kwargs.get(ATTR_HS_COLOR)
|
||||
|
||||
if brightness is not None:
|
||||
@ -144,10 +132,9 @@ class EufyHomeLight(LightEntity):
|
||||
self._brightness = 100
|
||||
brightness = self._brightness
|
||||
|
||||
if colortemp is not None:
|
||||
if color_temp_kelvin is not None:
|
||||
self._colormode = False
|
||||
temp_in_k = mired_to_kelvin(colortemp)
|
||||
relative_temp = temp_in_k - EUFYHOME_MIN_KELVIN
|
||||
relative_temp = color_temp_kelvin - EUFYHOME_MIN_KELVIN
|
||||
temp = int(
|
||||
relative_temp * 100 / (EUFYHOME_MAX_KELVIN - EUFYHOME_MIN_KELVIN)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user