1 """The ISY/IoX integration data models."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
6 from typing
import cast
9 from pyisy.constants
import PROTO_INSTEON
10 from pyisy.networking
import NetworkCommand
11 from pyisy.nodes
import Group, Node
12 from pyisy.programs
import Program
13 from pyisy.variables
import Variable
20 NODE_AUX_PROP_PLATFORMS,
30 """Data for the ISY/IoX integration."""
33 nodes: dict[Platform, list[Node | Group]]
34 root_nodes: dict[Platform, list[Node]]
35 variables: dict[Platform, list[Variable]]
36 programs: dict[Platform, list[tuple[str, Program, Program]]]
37 net_resources: list[NetworkCommand]
38 devices: dict[str, DeviceInfo]
39 aux_properties: dict[Platform, list[tuple[Node, str]]]
42 """Initialize an empty ISY data class."""
43 self.
nodesnodes = {p: []
for p
in NODE_PLATFORMS}
44 self.
root_nodesroot_nodes = {p: []
for p
in ROOT_NODE_PLATFORMS}
46 self.
programsprograms = {p: []
for p
in PROGRAM_PLATFORMS}
47 self.
variablesvariables = {p: []
for p
in VARIABLE_PLATFORMS}
53 """Return the ISY UUID identification."""
54 return cast(str, self.root.uuid)
56 def uid_base(self, node: Node | Group | Variable | Program | NetworkCommand) -> str:
57 """Return the unique id base string for a given node."""
58 if isinstance(node, NetworkCommand):
59 return f
"{self.uuid}_{CONF_NETWORK}_{node.address}"
60 return f
"{self.uuid}_{node.address}"
64 """Return all the unique ids for a config entry id."""
65 current_unique_ids: set[tuple[Platform, str]] = {
66 (Platform.BUTTON, f
"{self.uuid}_query")
70 for platform
in NODE_PLATFORMS:
71 for node
in self.
nodesnodes[platform]:
72 current_unique_ids.add((platform, self.
uid_baseuid_base(node)))
74 for platform
in NODE_AUX_PROP_PLATFORMS:
76 current_unique_ids.add((platform, f
"{self.uid_base(node)}_{control}"))
78 for platform
in PROGRAM_PLATFORMS:
79 for _, node, _
in self.
programsprograms[platform]:
80 current_unique_ids.add((platform, self.
uid_baseuid_base(node)))
82 for platform
in VARIABLE_PLATFORMS:
83 for node
in self.
variablesvariables[platform]:
84 current_unique_ids.add((platform, self.
uid_baseuid_base(node)))
85 if platform == Platform.NUMBER:
86 current_unique_ids.add((platform, f
"{self.uid_base(node)}_init"))
88 for platform
in ROOT_NODE_PLATFORMS:
89 for node
in self.
root_nodesroot_nodes[platform]:
90 current_unique_ids.add((platform, f
"{self.uid_base(node)}_query"))
91 if platform == Platform.BUTTON
and node.protocol == PROTO_INSTEON:
92 current_unique_ids.add((platform, f
"{self.uid_base(node)}_beep"))
95 current_unique_ids.add((Platform.BUTTON, self.
uid_baseuid_base(node)))
97 return current_unique_ids
str uid_base(self, Node|Group|Variable|Program|NetworkCommand node)
set[tuple[Platform, str]] unique_ids(self)