diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index eb3aa3a2239..445ff35793c 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -245,7 +245,7 @@ async def load_registries(hass: core.HomeAssistant) -> None: entity_registry.async_load(hass), issue_registry.async_load(hass), hass.async_add_executor_job(_cache_uname_processor), - template.async_load_custom_jinja(hass), + template.async_load_custom_templates(hass), ) diff --git a/homeassistant/components/homeassistant/__init__.py b/homeassistant/components/homeassistant/__init__.py index 4b033fd7119..91dd742e802 100644 --- a/homeassistant/components/homeassistant/__init__.py +++ b/homeassistant/components/homeassistant/__init__.py @@ -30,7 +30,7 @@ from homeassistant.helpers.service import ( async_extract_referenced_entity_ids, async_register_admin_service, ) -from homeassistant.helpers.template import async_load_custom_jinja +from homeassistant.helpers.template import async_load_custom_templates from homeassistant.helpers.typing import ConfigType ATTR_ENTRY_ID = "entry_id" @@ -39,7 +39,7 @@ _LOGGER = logging.getLogger(__name__) DOMAIN = ha.DOMAIN SERVICE_RELOAD_CORE_CONFIG = "reload_core_config" SERVICE_RELOAD_CONFIG_ENTRY = "reload_config_entry" -SERVICE_RELOAD_CUSTOM_JINJA = "reload_custom_jinja" +SERVICE_RELOAD_CUSTOM_TEMPLATES = "reload_custom_templates" SERVICE_CHECK_CONFIG = "check_config" SERVICE_UPDATE_ENTITY = "update_entity" SERVICE_SET_LOCATION = "set_location" @@ -260,12 +260,12 @@ async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # no vol.Schema({ATTR_LATITUDE: cv.latitude, ATTR_LONGITUDE: cv.longitude}), ) - async def async_handle_reload_jinja(call: ha.ServiceCall) -> None: + async def async_handle_reload_templates(call: ha.ServiceCall) -> None: """Service handler to reload custom Jinja.""" - await async_load_custom_jinja(hass) + await async_load_custom_templates(hass) async_register_admin_service( - hass, ha.DOMAIN, SERVICE_RELOAD_CUSTOM_JINJA, async_handle_reload_jinja + hass, ha.DOMAIN, SERVICE_RELOAD_CUSTOM_TEMPLATES, async_handle_reload_templates ) async def async_handle_reload_config_entry(call: ha.ServiceCall) -> None: @@ -300,7 +300,7 @@ async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # no Additionally, it also calls the `homeasssitant.reload_core_config` service, as that reloads the core YAML configuration, the `frontend.reload_themes` service that reloads the themes, and the - `homeassistant.reload_custom_jinja` service that reloads any custom + `homeassistant.reload_custom_templates` service that reloads any custom jinja into memory. We only do so, if there are no configuration errors. @@ -330,7 +330,7 @@ async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # no for domain, service in ( (ha.DOMAIN, SERVICE_RELOAD_CORE_CONFIG), ("frontend", "reload_themes"), - (ha.DOMAIN, SERVICE_RELOAD_CUSTOM_JINJA), + (ha.DOMAIN, SERVICE_RELOAD_CUSTOM_TEMPLATES), ) ] diff --git a/homeassistant/components/homeassistant/services.yaml b/homeassistant/components/homeassistant/services.yaml index 20f23402a73..2fe27769c3f 100644 --- a/homeassistant/components/homeassistant/services.yaml +++ b/homeassistant/components/homeassistant/services.yaml @@ -59,10 +59,10 @@ update_entity: target: entity: {} -reload_custom_jinja: +reload_custom_templates: name: Reload custom Jinja2 templates description: >- - Reload Jinja2 templates found in the custom_jinja folder in your config. + Reload Jinja2 templates found in the custom_templates folder in your config. New values will be applied on the next render of the template. reload_config_entry: diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index d3aa7c81ffb..481a59cee85 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -124,7 +124,7 @@ template_cv: ContextVar[tuple[str, str] | None] = ContextVar( CACHED_TEMPLATE_STATES = 512 EVAL_CACHE_SIZE = 512 -MAX_CUSTOM_JINJA_SIZE = 5 * 1024 * 1024 +MAX_CUSTOM_TEMPLATE_SIZE = 5 * 1024 * 1024 @bind_hass @@ -2084,18 +2084,18 @@ class LoggingUndefined(jinja2.Undefined): return super().__bool__() -async def async_load_custom_jinja(hass: HomeAssistant) -> None: +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_jinja, hass) + return await hass.async_add_executor_job(_load_custom_templates, hass) -def _load_custom_jinja(hass: HomeAssistant) -> None: +def _load_custom_templates(hass: HomeAssistant) -> None: result = {} - jinja_path = hass.config.path("custom_jinja") + jinja_path = hass.config.path("custom_templates") all_files = [ item for item in pathlib.Path(jinja_path).rglob("*.jinja") - if item.is_file() and item.stat().st_size <= MAX_CUSTOM_JINJA_SIZE + if item.is_file() and item.stat().st_size <= MAX_CUSTOM_TEMPLATE_SIZE ] for file in all_files: content = file.read_text() diff --git a/tests/components/homeassistant/test_init.py b/tests/components/homeassistant/test_init.py index 4a042416965..652fc4a1fdd 100644 --- a/tests/components/homeassistant/test_init.py +++ b/tests/components/homeassistant/test_init.py @@ -14,7 +14,7 @@ from homeassistant.components.homeassistant import ( SERVICE_CHECK_CONFIG, SERVICE_RELOAD_ALL, SERVICE_RELOAD_CORE_CONFIG, - SERVICE_RELOAD_CUSTOM_JINJA, + SERVICE_RELOAD_CUSTOM_TEMPLATES, SERVICE_SET_LOCATION, ) from homeassistant.const import ( @@ -576,19 +576,19 @@ async def test_save_persistent_states(hass: HomeAssistant) -> None: assert mock_save.called -async def test_reload_custom_jinja(hass: HomeAssistant) -> None: - """Test we can call reload_custom_jinja.""" +async def test_reload_custom_templates(hass: HomeAssistant) -> None: + """Test we can call reload_custom_templates.""" await async_setup_component(hass, "homeassistant", {}) with patch( - "homeassistant.components.homeassistant.async_load_custom_jinja", + "homeassistant.components.homeassistant.async_load_custom_templates", return_value=None, - ) as mock_load_custom_jinja: + ) as mock_load_custom_templates: await hass.services.async_call( "homeassistant", - SERVICE_RELOAD_CUSTOM_JINJA, + SERVICE_RELOAD_CUSTOM_TEMPLATES, blocking=True, ) - assert mock_load_custom_jinja.called + assert mock_load_custom_templates.called async def test_reload_all( @@ -602,7 +602,7 @@ async def test_reload_all( notify = async_mock_service(hass, "notify", "reload") core_config = async_mock_service(hass, "homeassistant", "reload_core_config") themes = async_mock_service(hass, "frontend", "reload_themes") - jinja = async_mock_service(hass, "homeassistant", "reload_custom_jinja") + jinja = async_mock_service(hass, "homeassistant", "reload_custom_templates") with patch( "homeassistant.config.async_check_ha_config_file", diff --git a/tests/helpers/test_template.py b/tests/helpers/test_template.py index 45237a5cbf0..b381775f1e1 100644 --- a/tests/helpers/test_template.py +++ b/tests/helpers/test_template.py @@ -245,8 +245,8 @@ def test_iterating_domain_states(hass: HomeAssistant) -> None: async def test_import(hass: HomeAssistant) -> None: - """Test that imports work from the config/custom_jinja folder.""" - await template.async_load_custom_jinja(hass) + """Test that imports work from the config/custom_templates folder.""" + await template.async_load_custom_templates(hass) assert "test.jinja" in template._get_hass_loader(hass).sources assert "inner/inner_test.jinja" in template._get_hass_loader(hass).sources assert ( @@ -283,7 +283,7 @@ async def test_import(hass: HomeAssistant) -> None: async def test_import_change(hass: HomeAssistant) -> None: """Test that a change in HassLoader results in updated imports.""" - await template.async_load_custom_jinja(hass) + await template.async_load_custom_templates(hass) to_test = template.Template( """ {% import 'test.jinja' as t %} diff --git a/tests/testing_config/custom_jinja/inner/inner_test.jinja b/tests/testing_config/custom_templates/inner/inner_test.jinja similarity index 100% rename from tests/testing_config/custom_jinja/inner/inner_test.jinja rename to tests/testing_config/custom_templates/inner/inner_test.jinja diff --git a/tests/testing_config/custom_jinja/test.jinja b/tests/testing_config/custom_templates/test.jinja similarity index 100% rename from tests/testing_config/custom_jinja/test.jinja rename to tests/testing_config/custom_templates/test.jinja