Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions homeassistant/components/eufy/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_HS_COLOR,
ColorMode,
LightEntity,
Expand All @@ -17,10 +17,6 @@
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
Expand All @@ -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."""

Expand Down Expand Up @@ -96,23 +95,12 @@ def brightness(self):
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):
Expand All @@ -134,7 +122,7 @@ def color_mode(self) -> ColorMode:
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:
Expand All @@ -144,10 +132,9 @@ def turn_on(self, **kwargs: Any) -> None:
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)
)
Expand Down