1 """Representation of ISYEntity Types."""
3 from __future__
import annotations
5 from typing
import Any, cast
7 from pyisy.constants
import (
10 COMMAND_FRIENDLY_NAME,
19 from pyisy.helpers
import EventListener, NodeProperty
20 from pyisy.nodes
import Group, Node, NodeChangedEvent
21 from pyisy.programs
import Program
22 from pyisy.variables
import Variable
30 from .const
import DOMAIN
34 """Representation of an ISY device."""
36 _attr_has_entity_name =
False
37 _attr_should_poll =
False
38 _node: Node | Program | Variable
42 node: Node | Group | Variable | Program,
43 device_info: DeviceInfo |
None =
None,
45 """Initialize the ISY/IoX entity."""
48 if device_info
is None:
49 device_info =
DeviceInfo(identifiers={(DOMAIN, node.isy.uuid)})
52 self._attrs: dict[str, Any] = {}
57 """Subscribe to the node change events."""
60 if hasattr(self.
_node_node,
"control_events"):
67 """Handle the update event from the ISY Node."""
72 """Handle a control event from the ISY Node."""
75 "control": event.control,
77 "formatted": event.formatted,
79 "precision": event.prec,
82 if event.control
not in EVENT_PROPS_IGNORED:
86 self.
hasshass.bus.async_fire(
"isy994_control", event_data)
90 """Representation of a ISY Nodebase (Node/Group) entity."""
94 node: Node | Group | Variable | Program,
95 device_info: DeviceInfo |
None =
None,
97 """Initialize the ISY/IoX node entity."""
98 super().
__init__(node, device_info=device_info)
99 if hasattr(node,
"parent_node")
and node.parent_node
is None:
105 """Return entity availability."""
106 return getattr(self.
_node_node, TAG_ENABLED,
True)
110 """Get the state attributes for the device.
112 The 'aux_properties' in the pyisy Node class are combined with the
113 other attributes which have been picked up from the event stream and
114 the combined result are returned as the device state attributes.
117 node = self.
_node_node
120 if node.protocol != PROTO_INSTEON
and hasattr(node,
"aux_properties"):
121 for name, value
in self.
_node_node.aux_properties.items():
122 attr_name = COMMAND_FRIENDLY_NAME.get(name, name)
123 attrs[attr_name] =
str(value.formatted).lower()
126 if hasattr(node,
"group_all_on"):
127 attrs[
"group_all_on"] = STATE_ON
if node.group_all_on
else STATE_OFF
132 """Respond to an entity service command call."""
133 if not hasattr(self.
_node_node, command):
135 f
"Invalid service call: {command} for device {self.entity_id}"
137 await getattr(self.
_node_node, command)()
142 value: Any |
None =
None,
143 unit_of_measurement: str |
None =
None,
144 parameters: Any |
None =
None,
146 """Respond to an entity service raw command call."""
147 if not hasattr(self.
_node_node,
"send_cmd"):
149 f
"Invalid service call: {command} for device {self.entity_id}"
151 await self.
_node_node.send_cmd(command, value, unit_of_measurement, parameters)
154 """Respond to an entity service command to request a Z-Wave device parameter from the ISY."""
155 if self.
_node_node.protocol != PROTO_ZWAVE:
157 "Invalid service call: cannot request Z-Wave Parameter for non-Z-Wave"
158 f
" device {self.entity_id}"
160 await self.
_node_node.get_zwave_parameter(parameter)
163 self, parameter: Any, value: Any |
None, size: int |
None
165 """Respond to an entity service command to set a Z-Wave device parameter via the ISY."""
166 if self.
_node_node.protocol != PROTO_ZWAVE:
168 "Invalid service call: cannot set Z-Wave Parameter for non-Z-Wave"
169 f
" device {self.entity_id}"
171 await self.
_node_node.set_zwave_parameter(parameter, value, size)
172 await self.
_node_node.get_zwave_parameter(parameter)
175 """Respond to an entity service command to rename a node on the ISY."""
176 await self.
_node_node.rename(name)
180 """Representation of an ISY program base."""
185 def __init__(self, name: str, status: Program, actions: Program =
None) ->
None:
186 """Initialize the ISY program-based entity."""
193 """Get the state attributes for the device."""
196 attr[
"actions_enabled"] = self.
_actions_actions.enabled
197 if self.
_actions_actions.last_finished != EMPTY_TIME:
198 attr[
"actions_last_finished"] = self.
_actions_actions.last_finished
199 if self.
_actions_actions.last_run != EMPTY_TIME:
200 attr[
"actions_last_run"] = self.
_actions_actions.last_run
201 if self.
_actions_actions.last_update != EMPTY_TIME:
202 attr[
"actions_last_update"] = self.
_actions_actions.last_update
203 attr[
"ran_else"] = self.
_actions_actions.ran_else
204 attr[
"ran_then"] = self.
_actions_actions.ran_then
205 attr[
"run_at_startup"] = self.
_actions_actions.run_at_startup
206 attr[
"running"] = self.
_actions_actions.running
207 attr[
"status_enabled"] = self.
_node_node.enabled
208 if self.
_node_node.last_finished != EMPTY_TIME:
209 attr[
"status_last_finished"] = self.
_node_node.last_finished
210 if self.
_node_node.last_run != EMPTY_TIME:
211 attr[
"status_last_run"] = self.
_node_node.last_run
212 if self.
_node_node.last_update != EMPTY_TIME:
213 attr[
"status_last_update"] = self.
_node_node.last_update
218 """Representation of a ISY/IoX Aux Control base entity."""
220 _attr_should_poll =
False
227 description: EntityDescription,
228 device_info: DeviceInfo |
None,
230 """Initialize the ISY Aux Control Number entity."""
233 name = COMMAND_FRIENDLY_NAME.get(control, control).replace(
"_",
" ").title()
234 if node.address != node.primary_node:
235 name = f
"{node.name} {name}"
245 """Subscribe to the node control change events."""
248 event_filter={ATTR_CONTROL: self.
_control_control},
254 TAG_ADDRESS: self.
_node_node.address,
255 ATTR_ACTION: NC_NODE_ENABLED,
262 """Handle a control event from the ISY Node."""
267 """Return entity availability."""
268 return cast(bool, self.
_node_node.enabled)
None async_on_update(self, NodeProperty|NodeChangedEvent event, str key)
None __init__(self, Node node, str control, str unique_id, EntityDescription description, DeviceInfo|None device_info)
None async_added_to_hass(self)
None async_added_to_hass(self)
None __init__(self, Node|Group|Variable|Program node, DeviceInfo|None device_info=None)
None async_on_update(self, NodeProperty event)
None async_on_control(self, NodeProperty event)
bool _attr_has_entity_name
None async_rename_node(self, str name)
None async_get_zwave_parameter(self, Any parameter)
None async_send_raw_node_command(self, str command, Any|None value=None, str|None unit_of_measurement=None, Any|None parameters=None)
dict extra_state_attributes(self)
None __init__(self, Node|Group|Variable|Program node, DeviceInfo|None device_info=None)
None async_set_zwave_parameter(self, Any parameter, Any|None value, int|None size)
None async_send_node_command(self, str command)
None __init__(self, str name, Program status, Program actions=None)
dict extra_state_attributes(self)
None async_write_ha_state(self)