1 """Support for ISY lights."""
3 from __future__
import annotations
5 from typing
import Any, cast
7 from pyisy.constants
import ISY_VALUE_UNKNOWN
8 from pyisy.helpers
import NodeProperty
9 from pyisy.nodes
import Node
19 from .const
import _LOGGER, CONF_RESTORE_LIGHT_STATE, DOMAIN, UOM_PERCENTAGE
20 from .entity
import ISYNodeEntity
21 from .models
import IsyData
23 ATTR_LAST_BRIGHTNESS =
"last_brightness"
27 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
29 """Set up the ISY light platform."""
30 isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
31 devices: dict[str, DeviceInfo] = isy_data.devices
32 isy_options = entry.options
33 restore_light_state = isy_options.get(CONF_RESTORE_LIGHT_STATE,
False)
36 ISYLightEntity(node, restore_light_state, devices.get(node.primary_node))
37 for node
in isy_data.nodes[Platform.LIGHT]
42 """Representation of an ISY light device."""
44 _attr_color_mode = ColorMode.BRIGHTNESS
45 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
50 restore_light_state: bool,
51 device_info: DeviceInfo |
None =
None,
53 """Initialize the ISY light device."""
54 super().
__init__(node, device_info=device_info)
60 """Get whether the ISY light is on."""
61 if self.
_node_node.status == ISY_VALUE_UNKNOWN:
63 return int(self.
_node_node.status) != 0
67 """Get the brightness of the ISY light."""
68 if self.
_node_node.status == ISY_VALUE_UNKNOWN:
71 if self.
_node_node.uom == UOM_PERCENTAGE:
72 return round(cast(float, self.
_node_node.status) * 255.0 / 100.0)
76 """Send the turn off command to the ISY light device."""
79 _LOGGER.debug(
"Unable to turn off light")
83 """Save brightness in the update event from the ISY Node."""
84 if self.
_node_node.status
not in (0, ISY_VALUE_UNKNOWN):
86 if self.
_node_node.uom == UOM_PERCENTAGE:
92 async
def async_turn_on(self, brightness: int |
None =
None, **kwargs: Any) ->
None:
93 """Send the turn on command to the ISY light device."""
97 if brightness
is not None and self.
_node_node.uom == UOM_PERCENTAGE:
98 brightness = round(brightness * 100.0 / 255.0)
100 _LOGGER.debug(
"Unable to turn on light")
104 """Return the light attributes."""
105 attribs = super().extra_state_attributes
110 """Restore last_brightness on restart."""
117 if last_brightness := last_state.attributes.get(ATTR_LAST_BRIGHTNESS):
dict[str, Any] extra_state_attributes(self)
None async_on_update(self, NodeProperty event)
None async_turn_on(self, int|None brightness=None, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None __init__(self, Node node, bool restore_light_state, DeviceInfo|None device_info=None)
None async_added_to_hass(self)
int|None brightness(self)
int|None brightness(self)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
State|None async_get_last_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)