1 """Support for ISY switches."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
8 from pyisy.constants
import (
15 from pyisy.helpers
import EventListener
16 from pyisy.nodes
import Node, NodeChangedEvent
21 SwitchEntityDescription,
30 from .const
import DOMAIN
31 from .entity
import ISYAuxControlEntity, ISYNodeEntity, ISYProgramEntity
32 from .models
import IsyData
35 @dataclass(frozen=True)
37 """Describes ISY switch."""
45 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
47 """Set up the ISY switch platform."""
48 isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
50 ISYSwitchProgramEntity | ISYSwitchEntity | ISYEnableSwitchEntity
52 device_info = isy_data.devices
53 for node
in isy_data.nodes[Platform.SWITCH]:
54 primary = node.primary_node
55 if node.protocol == PROTO_GROUP
and len(node.controllers) == 1:
57 primary = node.isy.nodes.get_by_id(node.controllers[0]).primary_node
61 for name, status, actions
in isy_data.programs[Platform.SWITCH]:
64 for node, control
in isy_data.aux_properties[Platform.SWITCH]:
69 device_class=SwitchDeviceClass.SWITCH,
71 entity_category=EntityCategory.CONFIG,
77 unique_id=f
"{isy_data.uid_base(node)}_{control}",
78 description=description,
79 device_info=device_info.get(node.primary_node),
86 """Representation of an ISY switch device."""
90 """Get whether the ISY device is in the on state."""
91 if self.
_node_node.status == ISY_VALUE_UNKNOWN:
96 """Send the turn off command to the ISY switch."""
101 """Send the turn on command to the ISY switch."""
107 """Get the icon for groups."""
108 if hasattr(self.
_node_node,
"protocol")
and self.
_node_node.protocol == PROTO_GROUP:
109 return "mdi:google-circles-communities"
114 """A representation of an ISY program switch."""
116 _attr_icon =
"mdi:script-text-outline"
120 """Get whether the ISY switch program is on."""
124 """Send the turn on command to the ISY switch program."""
125 if not await self.
_actions_actions.run_then():
127 f
"Unable to run 'then' clause on program switch {self._actions.address}"
131 """Send the turn off command to the ISY switch program."""
132 if not await self.
_actions_actions.run_else():
134 f
"Unable to run 'else' clause on program switch {self._actions.address}"
139 """A representation of an ISY enable/disable switch."""
146 description: ISYSwitchEntityDescription,
147 device_info: DeviceInfo |
None,
149 """Initialize the ISY Aux Control Number entity."""
154 description=description,
155 device_info=device_info,
162 """Subscribe to the node control change events."""
166 TAG_ADDRESS: self.
_node_node.address,
167 ATTR_ACTION: NC_NODE_ENABLED,
174 """Handle a control event from the ISY Node."""
179 """Return entity availability."""
184 """Get whether the ISY device is in the on state."""
188 """Send the turn off command to the ISY switch."""
193 """Send the turn on command to the ISY switch."""
None async_on_update(self, NodeProperty|NodeChangedEvent event, str key)
None async_added_to_hass(self)
None async_on_update(self, NodeChangedEvent event, str key)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None __init__(self, Node node, str control, str unique_id, ISYSwitchEntityDescription description, DeviceInfo|None device_info)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_write_ha_state(self)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)