mirror of
https://github.com/home-assistant/core.git
synced 2025-11-08 18:39:30 +00:00
Allow is_state_attr to check attributes for None (#132879)
This commit is contained in:
@@ -1970,7 +1970,7 @@ def test_is_state(hass: HomeAssistant) -> None:
|
||||
|
||||
def test_is_state_attr(hass: HomeAssistant) -> None:
|
||||
"""Test is_state_attr method."""
|
||||
hass.states.async_set("test.object", "available", {"mode": "on"})
|
||||
hass.states.async_set("test.object", "available", {"mode": "on", "exists": None})
|
||||
tpl = template.Template(
|
||||
"""
|
||||
{% if is_state_attr("test.object", "mode", "on") %}yes{% else %}no{% endif %}
|
||||
@@ -2003,6 +2003,22 @@ def test_is_state_attr(hass: HomeAssistant) -> None:
|
||||
)
|
||||
assert tpl.async_render() == "test.object"
|
||||
|
||||
tpl = template.Template(
|
||||
"""
|
||||
{% if is_state_attr("test.object", "exists", None) %}yes{% else %}no{% endif %}
|
||||
""",
|
||||
hass,
|
||||
)
|
||||
assert tpl.async_render() == "yes"
|
||||
|
||||
tpl = template.Template(
|
||||
"""
|
||||
{% if is_state_attr("test.object", "noexist", None) %}yes{% else %}no{% endif %}
|
||||
""",
|
||||
hass,
|
||||
)
|
||||
assert tpl.async_render() == "no"
|
||||
|
||||
|
||||
def test_state_attr(hass: HomeAssistant) -> None:
|
||||
"""Test state_attr method."""
|
||||
|
||||
Reference in New Issue
Block a user