mirror of
https://github.com/home-assistant/core.git
synced 2025-12-26 22:18:40 +00:00
Adds template function state_attr to get attribute from a state (#13378)
* Adds template function state_attr to get attribute from a state Refactored is_state_attr to use new function Adds tests for state_attr * Fixes line too long and test bug * Fixes pylint error * Fixes tests and D401 lint error
This commit is contained in:
committed by
Paulus Schoutsen
parent
00c6df54b2
commit
bdb4d754ae
@@ -397,6 +397,19 @@ class TestHelpersTemplate(unittest.TestCase):
|
||||
""", self.hass)
|
||||
self.assertEqual('False', tpl.render())
|
||||
|
||||
def test_state_attr(self):
|
||||
"""Test state_attr method."""
|
||||
self.hass.states.set('test.object', 'available', {'mode': 'on'})
|
||||
tpl = template.Template("""
|
||||
{% if state_attr("test.object", "mode") == "on" %}yes{% else %}no{% endif %}
|
||||
""", self.hass)
|
||||
self.assertEqual('yes', tpl.render())
|
||||
|
||||
tpl = template.Template("""
|
||||
{{ state_attr("test.noobject", "mode") == None }}
|
||||
""", self.hass)
|
||||
self.assertEqual('True', tpl.render())
|
||||
|
||||
def test_states_function(self):
|
||||
"""Test using states as a function."""
|
||||
self.hass.states.set('test.object', 'available')
|
||||
|
||||
Reference in New Issue
Block a user