Allow getting number of available states in template (#9158)

This commit is contained in:
Paulus Schoutsen 2017-08-27 09:33:25 -07:00 committed by Pascal Vizeli
parent c367021aa4
commit 5629157740
2 changed files with 22 additions and 0 deletions

View file

@ -782,3 +782,17 @@ def test_state_with_unit(hass):
hass)
assert tpl.async_render() == ''
@asyncio.coroutine
def test_length_of_states(hass):
"""Test fetching the length of states."""
hass.states.async_set('sensor.test', '23')
hass.states.async_set('sensor.test2', 'wow')
hass.states.async_set('climate.test2', 'cooling')
tpl = template.Template('{{ states | length }}', hass)
assert tpl.async_render() == '3'
tpl = template.Template('{{ states.sensor | length }}', hass)
assert tpl.async_render() == '2'