mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Update template environment from the event loop (#90758)
This commit is contained in:
parent
edd93e989e
commit
37661fe79f
@ -2173,10 +2173,11 @@ class LoggingUndefined(jinja2.Undefined):
|
|||||||
|
|
||||||
async def async_load_custom_templates(hass: HomeAssistant) -> None:
|
async def async_load_custom_templates(hass: HomeAssistant) -> None:
|
||||||
"""Load all custom jinja files under 5MiB into memory."""
|
"""Load all custom jinja files under 5MiB into memory."""
|
||||||
return await hass.async_add_executor_job(_load_custom_templates, hass)
|
custom_templates = await hass.async_add_executor_job(_load_custom_templates, hass)
|
||||||
|
_get_hass_loader(hass).sources = custom_templates
|
||||||
|
|
||||||
|
|
||||||
def _load_custom_templates(hass: HomeAssistant) -> None:
|
def _load_custom_templates(hass: HomeAssistant) -> dict[str, str]:
|
||||||
result = {}
|
result = {}
|
||||||
jinja_path = hass.config.path("custom_templates")
|
jinja_path = hass.config.path("custom_templates")
|
||||||
all_files = [
|
all_files = [
|
||||||
@ -2188,8 +2189,7 @@ def _load_custom_templates(hass: HomeAssistant) -> None:
|
|||||||
content = file.read_text()
|
content = file.read_text()
|
||||||
path = str(file.relative_to(jinja_path))
|
path = str(file.relative_to(jinja_path))
|
||||||
result[path] = content
|
result[path] = content
|
||||||
|
return result
|
||||||
_get_hass_loader(hass).sources = result
|
|
||||||
|
|
||||||
|
|
||||||
@singleton(_HASS_LOADER)
|
@singleton(_HASS_LOADER)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user