mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Add template is_state method
This commit is contained in:
parent
931f7e8615
commit
360b99be59
@ -41,8 +41,9 @@ def render(hass, template, variables=None, **kwargs):
|
||||
|
||||
try:
|
||||
return ENV.from_string(template, {
|
||||
'states': AllStates(hass)
|
||||
}).render(kwargs)
|
||||
'states': AllStates(hass),
|
||||
'is_state': hass.states.is_state
|
||||
}).render(kwargs).strip()
|
||||
except jinja2.TemplateError as err:
|
||||
raise TemplateError(err)
|
||||
|
||||
|
@ -100,3 +100,11 @@ class TestUtilTemplate(unittest.TestCase):
|
||||
def test_raise_exception_on_error(self):
|
||||
with self.assertRaises(TemplateError):
|
||||
template.render(self.hass, '{{ invalid_syntax')
|
||||
|
||||
def test_is_state(self):
|
||||
self.hass.states.set('test.object', 'available')
|
||||
self.assertEqual(
|
||||
'yes',
|
||||
template.render(
|
||||
self.hass,
|
||||
'{% if is_state("test.object", "available") %}yes{% else %}no{% endif %}'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user