Rename entry_id template method to config_entry_id (#80935)
parent
398d18eeee
commit
326344db12
|
@ -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"])
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue