Bypass dynamic validation for zwave_js custom triggers (#72471)
This commit is contained in:
parent
9b40de18cd
commit
c8c4bf6c37
4 changed files with 144 additions and 35 deletions
35
homeassistant/components/zwave_js/triggers/helpers.py
Normal file
35
homeassistant/components/zwave_js/triggers/helpers.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
"""Helpers for Z-Wave JS custom triggers."""
|
||||
from homeassistant.components.zwave_js.const import ATTR_CONFIG_ENTRY_ID, DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import ATTR_DEVICE_ID, ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
|
||||
@callback
|
||||
def async_bypass_dynamic_config_validation(
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> bool:
|
||||
"""Return whether target zwave_js config entry is not loaded."""
|
||||
# If the config entry is not loaded for a zwave_js device, entity, or the
|
||||
# config entry ID provided, we can't perform dynamic validation
|
||||
dev_reg = dr.async_get(hass)
|
||||
ent_reg = er.async_get(hass)
|
||||
trigger_devices = config.get(ATTR_DEVICE_ID, [])
|
||||
trigger_entities = config.get(ATTR_ENTITY_ID, [])
|
||||
return any(
|
||||
entry.state != ConfigEntryState.LOADED
|
||||
and (
|
||||
entry.entry_id == config.get(ATTR_CONFIG_ENTRY_ID)
|
||||
or any(
|
||||
device.id in trigger_devices
|
||||
for device in dr.async_entries_for_config_entry(dev_reg, entry.entry_id)
|
||||
)
|
||||
or (
|
||||
entity.entity_id in trigger_entities
|
||||
for entity in er.async_entries_for_config_entry(ent_reg, entry.entry_id)
|
||||
)
|
||||
)
|
||||
for entry in hass.config_entries.async_entries(DOMAIN)
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue