1 """The template component."""
3 from __future__
import annotations
6 from collections.abc
import Coroutine
10 from homeassistant
import config
as conf_util
22 async_remove_stale_devices_links_keep_current_device,
30 from .const
import CONF_MAX, CONF_MIN, CONF_STEP, CONF_TRIGGER, DOMAIN, PLATFORMS
31 from .coordinator
import TriggerUpdateCoordinator
32 from .helpers
import async_get_blueprints
34 _LOGGER = logging.getLogger(__name__)
35 DATA_COORDINATORS: HassKey[list[TriggerUpdateCoordinator]] =
HassKey(DOMAIN)
38 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
39 """Set up the template integration."""
49 hass.async_create_task(blueprints.async_populate(), eager_start=
True)
54 async
def _reload_config(call: Event | ServiceCall) ->
None:
55 """Reload top-level + platforms."""
57 unprocessed_conf = await conf_util.async_hass_config_yaml(hass)
58 except HomeAssistantError
as err:
63 conf = await conf_util.async_process_component_and_handle_errors(
64 hass, unprocessed_conf, integration
75 hass.bus.async_fire(f
"event_{DOMAIN}_reloaded", context=call.context)
83 """Set up a config entry."""
88 entry.options.get(CONF_DEVICE_ID),
91 for key
in (CONF_MAX, CONF_MIN, CONF_STEP):
92 if key
not in entry.options:
94 if isinstance(entry.options[key], str):
96 f
"The '{entry.options.get(CONF_NAME) or ""}' number template needs to "
97 f
"be reconfigured, {key} must be a number, got '{entry.options[key]}'"
100 await hass.config_entries.async_forward_entry_setups(
101 entry, (entry.options[
"template_type"],)
103 entry.async_on_unload(entry.add_update_listener(config_entry_update_listener))
108 """Update listener, called when the config entry options are changed."""
109 await hass.config_entries.async_reload(entry.entry_id)
113 """Unload a config entry."""
114 return await hass.config_entries.async_unload_platforms(
115 entry, (entry.options[
"template_type"],)
120 """Process config."""
121 coordinators = hass.data.pop(DATA_COORDINATORS,
None)
125 for coordinator
in coordinators:
126 coordinator.async_remove()
128 async
def init_coordinator(
129 hass: HomeAssistant, conf_section: dict[str, Any]
130 ) -> TriggerUpdateCoordinator:
132 await coordinator.async_setup(hass_config)
135 coordinator_tasks: list[Coroutine[Any, Any, TriggerUpdateCoordinator]] = []
137 for conf_section
in hass_config[DOMAIN]:
138 if CONF_TRIGGER
in conf_section:
139 coordinator_tasks.append(init_coordinator(hass, conf_section))
142 for platform_domain
in PLATFORMS:
143 if platform_domain
in conf_section:
144 hass.async_create_task(
145 discovery.async_load_platform(
150 "unique_id": conf_section.get(CONF_UNIQUE_ID),
154 "raw_blueprint_inputs": conf_section.raw_blueprint_inputs,
155 "raw_configs": conf_section.raw_config,
157 for entity_conf
in conf_section[platform_domain]
165 if coordinator_tasks:
166 hass.data[DATA_COORDINATORS] = await asyncio.gather(*coordinator_tasks)
blueprint.DomainBlueprints async_get_blueprints(HomeAssistant hass)
None _process_config(HomeAssistant hass, ConfigType hass_config)
bool async_setup(HomeAssistant hass, ConfigType config)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
None config_entry_update_listener(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
None async_remove_stale_devices_links_keep_current_device(HomeAssistant hass, str entry_id, str|None current_device_id)
None async_reload_integration_platforms(HomeAssistant hass, str integration_domain, Iterable[str] platform_domains)
None async_register_admin_service(HomeAssistant hass, str domain, str service, Callable[[ServiceCall], Awaitable[None]|None] service_func, VolSchemaType schema=vol.Schema({}, extra=vol.PREVENT_EXTRA))
Integration async_get_integration(HomeAssistant hass, str domain)