1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add template config_entry_attr function (#119899)

* Template config_entry_attr function

* Complete test coverage

* Improve readability
This commit is contained in:
Paulus Schoutsen
2024-06-22 21:51:09 -04:00
committed by GitHub
parent 22467cc575
commit bc45dcbad3
2 changed files with 64 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ import orjson
import pytest
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.components import group
from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT,
@@ -3990,6 +3991,48 @@ async def test_device_attr(
assert info.rate_limit is None
async def test_config_entry_attr(hass: HomeAssistant) -> None:
"""Test config entry attr."""
info = {
"domain": "mock_light",
"title": "mock title",
"source": config_entries.SOURCE_BLUETOOTH,
"disabled_by": config_entries.ConfigEntryDisabler.USER,
}
config_entry = MockConfigEntry(**info)
config_entry.add_to_hass(hass)
info["state"] = config_entries.ConfigEntryState.NOT_LOADED
for key, value in info.items():
tpl = template.Template(
"{{ config_entry_attr('" + config_entry.entry_id + "', '" + key + "') }}",
hass,
)
assert tpl.async_render(parse_result=False) == str(value)
for config_entry_id, key in (
(config_entry.entry_id, "invalid_key"),
(56, "domain"),
):
with pytest.raises(TemplateError):
template.Template(
"{{ config_entry_attr("
+ json.dumps(config_entry_id)
+ ", '"
+ key
+ "') }}",
hass,
).async_render()
assert (
template.Template(
"{{ config_entry_attr('invalid_id', 'domain') }}", hass
).async_render(parse_result=False)
== "None"
)
async def test_issues(hass: HomeAssistant, issue_registry: ir.IssueRegistry) -> None:
"""Test issues function."""
# Test no issues