diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index f04231ce78a..0db755e5115 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -1063,8 +1063,8 @@ def integration_entities(hass: HomeAssistant, entry_name: str) -> Iterable[str]: ] -def entry_id(hass: HomeAssistant, entity_id: str) -> str | None: - """Get an entry ID from an entity ID.""" +def config_entry_id(hass: HomeAssistant, entity_id: str) -> str | None: + """Get an config entry ID from an entity ID.""" entity_reg = entity_registry.async_get(hass) if entity := entity_reg.async_get(entity_id): return entity.config_entry_id @@ -2090,8 +2090,8 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment): self.globals["device_attr"] = hassfunction(device_attr) self.globals["is_device_attr"] = hassfunction(is_device_attr) - self.globals["entry_id"] = hassfunction(entry_id) - self.filters["entry_id"] = pass_context(self.globals["entry_id"]) + self.globals["config_entry_id"] = hassfunction(config_entry_id) + self.filters["config_entry_id"] = pass_context(self.globals["config_entry_id"]) self.globals["device_id"] = hassfunction(device_id) self.filters["device_id"] = pass_context(self.globals["device_id"]) diff --git a/tests/helpers/test_template.py b/tests/helpers/test_template.py index 2edb592ce39..28130bdb3bf 100644 --- a/tests/helpers/test_template.py +++ b/tests/helpers/test_template.py @@ -2474,8 +2474,8 @@ async def test_integration_entities(hass): assert info.rate_limit is None -async def test_entry_id(hass): - """Test entry_id function.""" +async def test_config_entry_id(hass): + """Test config_entry_id function.""" config_entry = MockConfigEntry(domain="light", title="Some integration") config_entry.add_to_hass(hass) entity_registry = mock_registry(hass) @@ -2483,17 +2483,19 @@ async def test_entry_id(hass): "sensor", "test", "test", suggested_object_id="test", config_entry=config_entry ) - info = render_to_info(hass, "{{ 'sensor.fail' | entry_id }}") + info = render_to_info(hass, "{{ 'sensor.fail' | config_entry_id }}") assert_result_info(info, None) assert info.rate_limit is None - info = render_to_info(hass, "{{ 56 | entry_id }}") + info = render_to_info(hass, "{{ 56 | config_entry_id }}") assert_result_info(info, None) - info = render_to_info(hass, "{{ 'not_a_real_entity_id' | entry_id }}") + info = render_to_info(hass, "{{ 'not_a_real_entity_id' | config_entry_id }}") assert_result_info(info, None) - info = render_to_info(hass, f"{{{{ entry_id('{entity_entry.entity_id}') }}}}") + info = render_to_info( + hass, f"{{{{ config_entry_id('{entity_entry.entity_id}') }}}}" + ) assert_result_info(info, config_entry.entry_id) assert info.rate_limit is None