Skip to content

Commit

Permalink
Rename entry_id template method to config_entry_id (home-assistant#80935
Browse files Browse the repository at this point in the history
)
  • Loading branch information
frenck authored Oct 25, 2022
1 parent 398d18e commit 326344d
Showing 2 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions homeassistant/helpers/template.py
Original file line number Diff line number Diff line change
@@ -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 @@ def wrapper(*args, **kwargs):
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"])
14 changes: 8 additions & 6 deletions tests/helpers/test_template.py
Original file line number Diff line number Diff line change
@@ -2474,26 +2474,28 @@ 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)
entity_entry = entity_registry.async_get_or_create(
"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

0 comments on commit 326344d

Please sign in to comment.