Update template environment from the event loop (#90758)

pull/90771/head
Erik Montnemery 2023-04-04 09:52:47 +02:00 committed by GitHub
parent edd93e989e
commit 37661fe79f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -2173,10 +2173,11 @@ class LoggingUndefined(jinja2.Undefined):
async def async_load_custom_templates(hass: HomeAssistant) -> None:
"""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 = {}
jinja_path = hass.config.path("custom_templates")
all_files = [
@ -2188,8 +2189,7 @@ def _load_custom_templates(hass: HomeAssistant) -> None:
content = file.read_text()
path = str(file.relative_to(jinja_path))
result[path] = content
_get_hass_loader(hass).sources = result
return result
@singleton(_HASS_LOADER)