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
20 changes: 8 additions & 12 deletions homeassistant/components/smartthings/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_COLOR_TEMP_KELVIN,
ATTR_HS_COLOR,
ATTR_TRANSITION,
ColorMode,
Expand All @@ -21,7 +21,6 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
import homeassistant.util.color as color_util

from .const import DATA_BROKERS, DOMAIN
from .entity import SmartThingsEntity
Expand Down Expand Up @@ -79,12 +78,12 @@ class SmartThingsLight(SmartThingsEntity, LightEntity):
# SmartThings does not expose this attribute, instead it's
# implemented within each device-type handler. This value is the
# lowest kelvin found supported across 20+ handlers.
_attr_max_mireds = 500 # 2000K
_attr_min_color_temp_kelvin = 2000 # 500 mireds

# SmartThings does not expose this attribute, instead it's
# implemented within each device-type handler. This value is the
# highest kelvin found supported across 20+ handlers.
_attr_min_mireds = 111 # 9000K
_attr_max_color_temp_kelvin = 9000 # 111 mireds

def __init__(self, device):
"""Initialize a SmartThingsLight."""
Expand Down Expand Up @@ -122,8 +121,8 @@ async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
tasks = []
# Color temperature
if ATTR_COLOR_TEMP in kwargs:
tasks.append(self.async_set_color_temp(kwargs[ATTR_COLOR_TEMP]))
if ATTR_COLOR_TEMP_KELVIN in kwargs:
tasks.append(self.async_set_color_temp(kwargs[ATTR_COLOR_TEMP_KELVIN]))
# Color
if ATTR_HS_COLOR in kwargs:
tasks.append(self.async_set_color(kwargs[ATTR_HS_COLOR]))
Expand Down Expand Up @@ -164,9 +163,7 @@ async def async_update(self) -> None:
)
# Color Temperature
if ColorMode.COLOR_TEMP in self._attr_supported_color_modes:
self._attr_color_temp = color_util.color_temperature_kelvin_to_mired(
self._device.status.color_temperature
)
self._attr_color_temp_kelvin = self._device.status.color_temperature
# Color
if ColorMode.HS in self._attr_supported_color_modes:
self._attr_hs_color = (
Expand All @@ -181,10 +178,9 @@ async def async_set_color(self, hs_color):
saturation = max(min(float(hs_color[1]), 100.0), 0.0)
await self._device.set_color(hue, saturation, set_status=True)

async def async_set_color_temp(self, value: float):
async def async_set_color_temp(self, value: int):
"""Set the color temperature of the device."""
kelvin = color_util.color_temperature_mired_to_kelvin(value)
kelvin = max(min(kelvin, 30000), 1)
kelvin = max(min(value, 30000), 1)
await self._device.set_color_temperature(kelvin, set_status=True)

async def async_set_level(self, brightness: int, transition: int):
Expand Down