Fix zwave_js trigger event reattach logic (#94702)

This commit is contained in:
Raman Gupta 2023-06-16 03:35:29 -04:00 committed by GitHub
parent 843a15b1bb
commit 934e1a1603
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 96 additions and 33 deletions

View file

@ -142,8 +142,9 @@ async def async_attach_trigger(
) -> CALLBACK_TYPE:
"""Listen for state changes based on configuration."""
dev_reg = dr.async_get(hass)
nodes = async_get_nodes_from_targets(hass, config, dev_reg=dev_reg)
if config[ATTR_EVENT_SOURCE] == "node" and not nodes:
if config[ATTR_EVENT_SOURCE] == "node" and not async_get_nodes_from_targets(
hass, config, dev_reg=dev_reg
):
raise ValueError(
f"No nodes found for given {ATTR_DEVICE_ID}s or {ATTR_ENTITY_ID}s."
)
@ -215,7 +216,7 @@ async def async_attach_trigger(
# Nodes list can come from different drivers and we will need to listen to
# server connections for all of them.
drivers: set[Driver] = set()
if not nodes:
if not (nodes := async_get_nodes_from_targets(hass, config, dev_reg=dev_reg)):
entry_id = config[ATTR_CONFIG_ENTRY_ID]
client: Client = hass.data[DOMAIN][entry_id][DATA_CLIENT]
driver = client.driver