Skip to content
Merged
Show file tree
Hide file tree
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
31 changes: 20 additions & 11 deletions homeassistant/components/elgato/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 @@ -19,6 +19,7 @@
AddEntitiesCallback,
async_get_current_platform,
)
from homeassistant.util import color as color_util

from . import ElgatorConfigEntry
from .const import SERVICE_IDENTIFY
Expand Down Expand Up @@ -49,8 +50,8 @@ class ElgatoLight(ElgatoEntity, LightEntity):
"""Defines an Elgato Light."""

_attr_name = None
_attr_min_mireds = 143
_attr_max_mireds = 344
_attr_min_color_temp_kelvin = 2900 # 344 Mireds
_attr_max_color_temp_kelvin = 7000 # 143 Mireds

def __init__(self, coordinator: ElgatoDataUpdateCoordinator) -> None:
"""Initialize Elgato Light."""
Expand All @@ -69,18 +70,20 @@ def __init__(self, coordinator: ElgatoDataUpdateCoordinator) -> None:
or self.coordinator.data.state.hue is not None
):
self._attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS}
self._attr_min_mireds = 153
self._attr_max_mireds = 285
self._attr_min_color_temp_kelvin = 3500 # 285 Mireds
self._attr_max_color_temp_kelvin = 6500 # 153 Mireds

@property
def brightness(self) -> int | None:
"""Return the brightness of this light between 1..255."""
return round((self.coordinator.data.state.brightness * 255) / 100)

@property
def color_temp(self) -> int | None:
"""Return the CT color value in mireds."""
return self.coordinator.data.state.temperature
def color_temp_kelvin(self) -> int | None:
"""Return the color temperature value in Kelvin."""
if (mired_temperature := self.coordinator.data.state.temperature) is None:
return None
return color_util.color_temperature_mired_to_kelvin(mired_temperature)

@property
def color_mode(self) -> str | None:
Expand Down Expand Up @@ -116,7 +119,7 @@ async def async_turn_off(self, **kwargs: Any) -> None:

async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the light."""
temperature = kwargs.get(ATTR_COLOR_TEMP)
temperature_kelvin = kwargs.get(ATTR_COLOR_TEMP_KELVIN)

hue = None
saturation = None
Expand All @@ -133,12 +136,18 @@ async def async_turn_on(self, **kwargs: Any) -> None:
if (
brightness
and ATTR_HS_COLOR not in kwargs
and ATTR_COLOR_TEMP not in kwargs
and ATTR_COLOR_TEMP_KELVIN not in kwargs
and self.supported_color_modes
and ColorMode.HS in self.supported_color_modes
and self.color_mode == ColorMode.COLOR_TEMP
):
temperature = self.color_temp
temperature_kelvin = self.color_temp_kelvin

temperature = (
None
if temperature_kelvin is None
else color_util.color_temperature_kelvin_to_mired(temperature_kelvin)
)

try:
await self.coordinator.client.light(
Expand Down
28 changes: 14 additions & 14 deletions tests/components/elgato/snapshots/test_light.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
27.316,
47.743,
),
'max_color_temp_kelvin': 6993,
'max_color_temp_kelvin': 7000,
'max_mireds': 344,
'min_color_temp_kelvin': 2906,
'min_mireds': 143,
'min_color_temp_kelvin': 2900,
'min_mireds': 142,
'rgb_color': tuple(
255,
189,
Expand Down Expand Up @@ -43,10 +43,10 @@
}),
'area_id': None,
'capabilities': dict({
'max_color_temp_kelvin': 6993,
'max_color_temp_kelvin': 7000,
'max_mireds': 344,
'min_color_temp_kelvin': 2906,
'min_mireds': 143,
'min_color_temp_kelvin': 2900,
'min_mireds': 142,
'supported_color_modes': list([
<ColorMode.COLOR_TEMP: 'color_temp'>,
]),
Expand Down Expand Up @@ -126,9 +126,9 @@
27.316,
47.743,
),
'max_color_temp_kelvin': 6535,
'max_color_temp_kelvin': 6500,
'max_mireds': 285,
'min_color_temp_kelvin': 3508,
'min_color_temp_kelvin': 3500,
'min_mireds': 153,
'rgb_color': tuple(
255,
Expand Down Expand Up @@ -159,9 +159,9 @@
}),
'area_id': None,
'capabilities': dict({
'max_color_temp_kelvin': 6535,
'max_color_temp_kelvin': 6500,
'max_mireds': 285,
'min_color_temp_kelvin': 3508,
'min_color_temp_kelvin': 3500,
'min_mireds': 153,
'supported_color_modes': list([
<ColorMode.COLOR_TEMP: 'color_temp'>,
Expand Down Expand Up @@ -243,9 +243,9 @@
358.0,
6.0,
),
'max_color_temp_kelvin': 6535,
'max_color_temp_kelvin': 6500,
'max_mireds': 285,
'min_color_temp_kelvin': 3508,
'min_color_temp_kelvin': 3500,
'min_mireds': 153,
'rgb_color': tuple(
255,
Expand Down Expand Up @@ -276,9 +276,9 @@
}),
'area_id': None,
'capabilities': dict({
'max_color_temp_kelvin': 6535,
'max_color_temp_kelvin': 6500,
'max_mireds': 285,
'min_color_temp_kelvin': 3508,
'min_color_temp_kelvin': 3500,
'min_mireds': 153,
'supported_color_modes': list([
<ColorMode.COLOR_TEMP: 'color_temp'>,
Expand Down