Home Assistant Unofficial Reference 2024.12.1
helpers.py
Go to the documentation of this file.
1 """Helpers for automation integration."""
2 
3 from homeassistant.components import blueprint
4 from homeassistant.const import SERVICE_RELOAD
5 from homeassistant.core import HomeAssistant, callback
6 from homeassistant.helpers.singleton import singleton
7 
8 from .const import DOMAIN, LOGGER
9 
10 DATA_BLUEPRINTS = "automation_blueprints"
11 
12 
13 def _blueprint_in_use(hass: HomeAssistant, blueprint_path: str) -> bool:
14  """Return True if any automation references the blueprint."""
15  from . import automations_with_blueprint # pylint: disable=import-outside-toplevel
16 
17  return len(automations_with_blueprint(hass, blueprint_path)) > 0
18 
19 
21  hass: HomeAssistant, blueprint_path: str
22 ) -> None:
23  """Reload all automations that rely on a specific blueprint."""
24  await hass.services.async_call(DOMAIN, SERVICE_RELOAD)
25 
26 
27 @singleton(DATA_BLUEPRINTS)
28 @callback
30  """Get automation blueprints."""
31  # pylint: disable-next=import-outside-toplevel
32  from .config import AUTOMATION_BLUEPRINT_SCHEMA
33 
35  hass,
36  DOMAIN,
37  LOGGER,
38  _blueprint_in_use,
39  _reload_blueprint_automations,
40  AUTOMATION_BLUEPRINT_SCHEMA,
41  )
bool _blueprint_in_use(HomeAssistant hass, str blueprint_path)
Definition: helpers.py:13
None _reload_blueprint_automations(HomeAssistant hass, str blueprint_path)
Definition: helpers.py:22
blueprint.DomainBlueprints async_get_blueprints(HomeAssistant hass)
Definition: helpers.py:29
list[str] automations_with_blueprint(HomeAssistant hass, str blueprint_path)
Definition: __init__.py:251