1 """Support for Lutron Caseta lights."""
3 from datetime
import timedelta
6 from pylutron_caseta.color_value
import (
7 ColorMode
as LutronColorMode,
14 ATTR_COLOR_TEMP_KELVIN,
18 DOMAIN
as LIGHT_DOMAIN,
27 from .const
import DEVICE_TYPE_SPECTRUM_TUNE, DEVICE_TYPE_WHITE_TUNE
28 from .entity
import LutronCasetaUpdatableEntity
29 from .models
import LutronCasetaData
31 SUPPORTED_COLOR_MODE_DICT = {
32 DEVICE_TYPE_SPECTRUM_TUNE: {
37 DEVICE_TYPE_WHITE_TUNE: {ColorMode.COLOR_TEMP},
40 WARM_DEVICE_TYPES = {DEVICE_TYPE_WHITE_TUNE, DEVICE_TYPE_SPECTRUM_TUNE}
44 """Convert the given Home Assistant light level (0-255) to Lutron (0-100)."""
45 return int(round((level * 100) / 255))
49 """Convert the given Lutron (0-100) light level to Home Assistant (0-255)."""
50 return int((level * 255) // 100)
55 config_entry: ConfigEntry,
56 async_add_entities: AddEntitiesCallback,
58 """Set up the Lutron Caseta light platform.
60 Adds dimmers from the Caseta bridge associated with the config_entry as
63 data = config_entry.runtime_data
65 light_devices = bridge.get_devices_by_domain(LIGHT_DOMAIN)
72 """Representation of a Lutron Light, including dimmable, white tune, and spectrum tune."""
74 _attr_supported_features = LightEntityFeature.TRANSITION
76 def __init__(self, light: dict[str, Any], data: LutronCasetaData) ->
None:
77 """Initialize the light and set the supported color modes.
79 :param light: The lutron light device to initialize.
80 :param data: The integration data
87 light_type = light[
"type"]
89 light_type, {ColorMode.BRIGHTNESS}
97 """Return minimum supported color temperature.
99 :param light: The light to get the minimum color temperature for.
101 white_tune_range = light.get(
"white_tuning_range")
103 if white_tune_range
is None or "Min" not in white_tune_range:
106 return white_tune_range.get(
"Min")
109 """Return maximum supported color temperature.
111 :param light: The light to get the maximum color temperature for.
113 white_tune_range = light.get(
"white_tuning_range")
115 if white_tune_range
is None or "Max" not in white_tune_range:
118 return white_tune_range.get(
"Max")
122 """Return the brightness of the light."""
126 self, brightness: int |
None, color_value: LutronColorMode |
None, **kwargs: Any
129 if ATTR_TRANSITION
in kwargs:
130 args[
"fade_time"] =
timedelta(seconds=kwargs[ATTR_TRANSITION])
132 if brightness
is not None:
135 self.
device_iddevice_id, value=brightness, color_value=color_value, **args
139 """Set the light to warm dim mode."""
140 set_warm_dim_kwargs: dict[str, Any] = {}
141 if ATTR_TRANSITION
in kwargs:
142 set_warm_dim_kwargs[
"fade_time"] =
timedelta(
143 seconds=kwargs[ATTR_TRANSITION]
146 if brightness
is not None:
150 self.
device_iddevice_id, brightness, **set_warm_dim_kwargs
154 """Turn the light on."""
156 if (white_color := kwargs.get(ATTR_WHITE))
is not None:
160 brightness = kwargs.pop(ATTR_BRIGHTNESS,
None)
161 color: LutronColorMode |
None =
None
162 hs_color: tuple[float, float] |
None = kwargs.pop(ATTR_HS_COLOR,
None)
163 kelvin_color: int |
None = kwargs.pop(ATTR_COLOR_TEMP_KELVIN,
None)
165 if hs_color
is not None:
166 color = FullColorValue(hs_color[0], hs_color[1])
167 elif kelvin_color
is not None:
168 color = WarmCoolColorValue(kelvin_color)
171 if color
is None and brightness
is None:
177 """Turn the light off."""
182 """Return the current color mode of the light."""
186 return ColorMode.WHITE
189 if self.
supports_warm_coolsupports_warm_cool
and isinstance(current_color, WarmCoolColorValue):
190 return ColorMode.COLOR_TEMP
195 return ColorMode.BRIGHTNESS
199 """Return true if device is on."""
204 """Return the current color of the light."""
205 current_color: FullColorValue | WarmCoolColorValue |
None = self.
_device_device_device.
get(
210 if isinstance(current_color, FullColorValue):
211 return (current_color.hue, current_color.saturation)
217 """Return the CT color value in kelvin."""
218 current_color: FullColorValue | WarmCoolColorValue |
None = self.
_device_device_device.
get(
223 if isinstance(current_color, WarmCoolColorValue):
224 return current_color.kelvin
None __init__(self, dict[str, Any] light, LutronCasetaData data)
_attr_supported_color_modes
_attr_min_color_temp_kelvin
None async_turn_off(self, **Any kwargs)
def _async_set_warm_dim(self, int|None brightness, **Any kwargs)
None async_turn_on(self, **Any kwargs)
int _get_min_color_temp_kelvin(self, dict[str, Any] light)
ColorMode color_mode(self)
int|None color_temp_kelvin(self)
None _async_set_brightness(self, int|None brightness, LutronColorMode|None color_value, **Any kwargs)
int _get_max_color_temp_kelvin(self, dict[str, Any] light)
tuple[float, float]|None hs_color(self)
_attr_max_color_temp_kelvin
web.Response get(self, web.Request request, str config_key)
def to_lutron_level(level)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)