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.blueprint import BLUEPRINT_SCHEMA, DomainBlueprints
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 = "script_blueprints"
11 
12 
13 def _blueprint_in_use(hass: HomeAssistant, blueprint_path: str) -> bool:
14  """Return True if any script references the blueprint."""
15  from . import scripts_with_blueprint # pylint: disable=import-outside-toplevel
16 
17  return len(scripts_with_blueprint(hass, blueprint_path)) > 0
18 
19 
20 async def _reload_blueprint_scripts(hass: HomeAssistant, blueprint_path: str) -> None:
21  """Reload all script that rely on a specific blueprint."""
22  await hass.services.async_call(DOMAIN, SERVICE_RELOAD)
23 
24 
25 @singleton(DATA_BLUEPRINTS)
26 @callback
27 def async_get_blueprints(hass: HomeAssistant) -> DomainBlueprints:
28  """Get script blueprints."""
29  return DomainBlueprints(
30  hass,
31  DOMAIN,
32  LOGGER,
33  _blueprint_in_use,
34  _reload_blueprint_scripts,
35  BLUEPRINT_SCHEMA,
36  )
None _reload_blueprint_scripts(HomeAssistant hass, str blueprint_path)
Definition: helpers.py:20
DomainBlueprints async_get_blueprints(HomeAssistant hass)
Definition: helpers.py:27
bool _blueprint_in_use(HomeAssistant hass, str blueprint_path)
Definition: helpers.py:13
list[str] scripts_with_blueprint(HomeAssistant hass, str blueprint_path)
Definition: __init__.py:186