mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Allow device_attr
and is_device_attr
to be used as a filter and a test (respectively) (#81924)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
8a8732f0bc
commit
9dd1b85cbb
@ -2094,7 +2094,10 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment):
|
||||
self.filters["device_entities"] = pass_context(self.globals["device_entities"])
|
||||
|
||||
self.globals["device_attr"] = hassfunction(device_attr)
|
||||
self.filters["device_attr"] = pass_context(self.globals["device_attr"])
|
||||
|
||||
self.globals["is_device_attr"] = hassfunction(is_device_attr)
|
||||
self.tests["is_device_attr"] = pass_eval_context(self.globals["is_device_attr"])
|
||||
|
||||
self.globals["config_entry_id"] = hassfunction(config_entry_id)
|
||||
self.filters["config_entry_id"] = pass_context(self.globals["config_entry_id"])
|
||||
|
@ -2738,6 +2738,21 @@ async def test_device_attr(hass: HomeAssistant) -> None:
|
||||
assert_result_info(info, True)
|
||||
assert info.rate_limit is None
|
||||
|
||||
# Test filter syntax (device_attr)
|
||||
info = render_to_info(
|
||||
hass, f"{{{{ '{entity_entry.entity_id}' | device_attr('model') }}}}"
|
||||
)
|
||||
assert_result_info(info, "test")
|
||||
assert info.rate_limit is None
|
||||
|
||||
# Test test syntax (is_device_attr)
|
||||
info = render_to_info(
|
||||
hass,
|
||||
f"{{{{ ['{device_entry.id}'] | select('is_device_attr', 'model', 'test') | list }}}}",
|
||||
)
|
||||
assert_result_info(info, [device_entry.id])
|
||||
assert info.rate_limit is None
|
||||
|
||||
|
||||
async def test_area_id(hass: HomeAssistant) -> None:
|
||||
"""Test area_id function."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user