Consolidate device info and clean-up ISY994 code base (#85657)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
43cc8a1ebf
commit
255a8362a1
21 changed files with 481 additions and 446 deletions
|
@ -1,40 +1,69 @@
|
|||
"""ISY utils."""
|
||||
from __future__ import annotations
|
||||
|
||||
from pyisy.constants import PROP_COMMS_ERROR, PROTO_INSTEON
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import (
|
||||
CONF_NETWORK,
|
||||
DOMAIN,
|
||||
ISY994_ISY,
|
||||
ISY994_NODES,
|
||||
ISY994_PROGRAMS,
|
||||
ISY994_VARIABLES,
|
||||
ISY_CONF_UUID,
|
||||
PLATFORMS,
|
||||
ISY_NET_RES,
|
||||
ISY_NODES,
|
||||
ISY_PROGRAMS,
|
||||
ISY_ROOT,
|
||||
ISY_ROOT_NODES,
|
||||
ISY_VARIABLES,
|
||||
NODE_PLATFORMS,
|
||||
PROGRAM_PLATFORMS,
|
||||
ROOT_NODE_PLATFORMS,
|
||||
SENSOR_AUX,
|
||||
)
|
||||
|
||||
|
||||
def unique_ids_for_config_entry_id(
|
||||
hass: HomeAssistant, config_entry_id: str
|
||||
) -> set[str]:
|
||||
) -> set[tuple[Platform | str, str]]:
|
||||
"""Find all the unique ids for a config entry id."""
|
||||
hass_isy_data = hass.data[DOMAIN][config_entry_id]
|
||||
uuid = hass_isy_data[ISY994_ISY].configuration[ISY_CONF_UUID]
|
||||
current_unique_ids: set[str] = {uuid}
|
||||
isy = hass_isy_data[ISY_ROOT]
|
||||
current_unique_ids: set[tuple[Platform | str, str]] = {
|
||||
(Platform.BUTTON, f"{isy.uuid}_query")
|
||||
}
|
||||
|
||||
for platform in PLATFORMS:
|
||||
for node in hass_isy_data[ISY994_NODES][platform]:
|
||||
if hasattr(node, "address"):
|
||||
current_unique_ids.add(f"{uuid}_{node.address}")
|
||||
# Structure and prefixes here must match what's added in __init__ and helpers
|
||||
for platform in NODE_PLATFORMS:
|
||||
for node in hass_isy_data[ISY_NODES][platform]:
|
||||
current_unique_ids.add((platform, f"{isy.uuid}_{node.address}"))
|
||||
|
||||
for node, control in hass_isy_data[ISY_NODES][SENSOR_AUX]:
|
||||
current_unique_ids.add(
|
||||
(Platform.SENSOR, f"{isy.uuid}_{node.address}_{control}")
|
||||
)
|
||||
current_unique_ids.add(
|
||||
(Platform.SENSOR, f"{isy.uuid}_{node.address}_{PROP_COMMS_ERROR}")
|
||||
)
|
||||
|
||||
for platform in PROGRAM_PLATFORMS:
|
||||
for _, node, _ in hass_isy_data[ISY994_PROGRAMS][platform]:
|
||||
if hasattr(node, "address"):
|
||||
current_unique_ids.add(f"{uuid}_{node.address}")
|
||||
for _, node, _ in hass_isy_data[ISY_PROGRAMS][platform]:
|
||||
current_unique_ids.add((platform, f"{isy.uuid}_{node.address}"))
|
||||
|
||||
for node in hass_isy_data[ISY994_VARIABLES]:
|
||||
if hasattr(node, "address"):
|
||||
current_unique_ids.add(f"{uuid}_{node.address}")
|
||||
for node, _ in hass_isy_data[ISY_VARIABLES][Platform.NUMBER]:
|
||||
current_unique_ids.add((Platform.NUMBER, f"{isy.uuid}_{node.address}"))
|
||||
current_unique_ids.add((Platform.NUMBER, f"{isy.uuid}_{node.address}_init"))
|
||||
for _, node in hass_isy_data[ISY_VARIABLES][Platform.SENSOR]:
|
||||
current_unique_ids.add((Platform.SENSOR, f"{isy.uuid}_{node.address}"))
|
||||
|
||||
for platform in ROOT_NODE_PLATFORMS:
|
||||
for node in hass_isy_data[ISY_ROOT_NODES][platform]:
|
||||
current_unique_ids.add((platform, f"{isy.uuid}_{node.address}_query"))
|
||||
if platform == Platform.BUTTON and node.protocol == PROTO_INSTEON:
|
||||
current_unique_ids.add((platform, f"{isy.uuid}_{node.address}_beep"))
|
||||
|
||||
for node in hass_isy_data[ISY_NET_RES]:
|
||||
current_unique_ids.add(
|
||||
(Platform.BUTTON, f"{isy.uuid}_{CONF_NETWORK}_{node.address}")
|
||||
)
|
||||
|
||||
return current_unique_ids
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue