mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Migrate smartthings lights to use Kelvin (#132699)
This commit is contained in:
parent
abc79a9f1c
commit
dcbedb5ae5
@ -10,7 +10,7 @@ from pysmartthings import Capability
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_COLOR_TEMP,
|
||||
ATTR_COLOR_TEMP_KELVIN,
|
||||
ATTR_HS_COLOR,
|
||||
ATTR_TRANSITION,
|
||||
ColorMode,
|
||||
@ -21,7 +21,6 @@ from homeassistant.components.light import (
|
||||
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
|
||||
@ -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."""
|
||||
@ -122,8 +121,8 @@ class SmartThingsLight(SmartThingsEntity, LightEntity):
|
||||
"""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]))
|
||||
@ -164,9 +163,7 @@ class SmartThingsLight(SmartThingsEntity, LightEntity):
|
||||
)
|
||||
# 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 = (
|
||||
@ -181,10 +178,9 @@ class SmartThingsLight(SmartThingsEntity, LightEntity):
|
||||
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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user