Home Assistant Unofficial Reference 2024.12.1
trigger_helpers.py
Go to the documentation of this file.
1 """Helpers for Z-Wave JS custom triggers."""
2 
3 from zwave_js_server.client import Client as ZwaveClient
4 
5 from homeassistant.config_entries import ConfigEntryState
6 from homeassistant.const import ATTR_DEVICE_ID, ATTR_ENTITY_ID
7 from homeassistant.core import HomeAssistant, callback
8 from homeassistant.helpers import device_registry as dr, entity_registry as er
9 from homeassistant.helpers.typing import ConfigType
10 
11 from ..const import ATTR_CONFIG_ENTRY_ID, DATA_CLIENT, DOMAIN
12 
13 
14 @callback
16  hass: HomeAssistant, config: ConfigType
17 ) -> bool:
18  """Return whether target zwave_js config entry is not loaded."""
19  # If the config entry is not loaded for a zwave_js device, entity, or the
20  # config entry ID provided, we can't perform dynamic validation
21  dev_reg = dr.async_get(hass)
22  ent_reg = er.async_get(hass)
23  trigger_devices = config.get(ATTR_DEVICE_ID, [])
24  trigger_entities = config.get(ATTR_ENTITY_ID, [])
25  for entry in hass.config_entries.async_entries(DOMAIN):
26  if entry.state != ConfigEntryState.LOADED and (
27  entry.entry_id == config.get(ATTR_CONFIG_ENTRY_ID)
28  or any(
29  device.id in trigger_devices
30  for device in dr.async_entries_for_config_entry(dev_reg, entry.entry_id)
31  )
32  or (
33  entity.entity_id in trigger_entities
34  for entity in er.async_entries_for_config_entry(ent_reg, entry.entry_id)
35  )
36  ):
37  return True
38 
39  # The driver may not be ready when the config entry is loaded.
40  client: ZwaveClient = entry.runtime_data[DATA_CLIENT]
41  if client.driver is None:
42  return True
43 
44  return False
bool async_bypass_dynamic_config_validation(HomeAssistant hass, ConfigType config)