1 """Support for Lutron lights."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from pylutron
import Output
22 from .
import DOMAIN, LutronData
23 from .entity
import LutronDevice
28 config_entry: ConfigEntry,
29 async_add_entities: AddEntitiesCallback,
31 """Set up the Lutron light platform.
33 Adds dimmers from the Main Repeater associated with the config_entry as
36 entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id]
41 for area_name, device
in entry_data.lights
48 """Convert the given Home Assistant light level (0-255) to Lutron (0.0-100.0)."""
49 return float((level * 100) / 255)
53 """Convert the given Lutron (0.0-100.0) light level to Home Assistant (0-255)."""
54 return int((level * 255) / 100)
58 """Representation of a Lutron Light, including dimmable."""
60 _attr_color_mode = ColorMode.BRIGHTNESS
61 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
62 _attr_supported_features = LightEntityFeature.TRANSITION | LightEntityFeature.FLASH
63 _lutron_device: Output
64 _prev_brightness: int |
None =
None
68 """Turn the light on."""
69 if flash := kwargs.get(ATTR_FLASH):
70 self.
_lutron_device_lutron_device.flash(0.5
if flash ==
"short" else 1.5)
72 if ATTR_BRIGHTNESS
in kwargs
and self.
_lutron_device_lutron_device.is_dimmable:
73 brightness = kwargs[ATTR_BRIGHTNESS]
80 if ATTR_TRANSITION
in kwargs:
81 args[
"fade_time_seconds"] = kwargs[ATTR_TRANSITION]
85 """Turn the light off."""
86 args = {
"new_level": 0}
87 if ATTR_TRANSITION
in kwargs:
88 args[
"fade_time_seconds"] = kwargs[ATTR_TRANSITION]
93 """Return the state attributes."""
94 return {
"lutron_integration_id": self.
_lutron_device_lutron_device.id}
97 """Request the state from the device."""
101 """Update the state attributes."""
None turn_on(self, **Any kwargs)
None turn_off(self, **Any kwargs)
None _request_state(self)
Mapping[str, Any]|None extra_state_attributes(self)
def to_lutron_level(level)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)