Implemented event_data_template (new) (#11057)

* Implemented event_data_template

* The hound does not like my indentation

* Added passed variables to tests for event and svc template calls

* Moved recursive function to template.py

* Update template.py

* Update template.py

* Cleaned up service.py and fixed unit tests

* Blank lines

* Removed stray logger statement

* Blank lines again
This commit is contained in:
tschmidty69 2018-01-19 01:13:14 -05:00 committed by Paulus Schoutsen
parent 0e1cc05189
commit 48619c9d7c
6 changed files with 101 additions and 19 deletions

View file

@ -279,6 +279,36 @@ class TestHelpersTemplate(unittest.TestCase):
'127',
template.Template('{{ hello }}', self.hass).render({'hello': 127}))
def test_passing_vars_as_list(self):
"""Test passing variables as list."""
self.assertEqual(
"['foo', 'bar']",
template.render_complex(template.Template('{{ hello }}',
self.hass), {'hello': ['foo', 'bar']}))
def test_passing_vars_as_list_element(self):
"""Test passing variables as list."""
self.assertEqual(
'bar',
template.render_complex(template.Template('{{ hello[1] }}',
self.hass),
{'hello': ['foo', 'bar']}))
def test_passing_vars_as_dict_element(self):
"""Test passing variables as list."""
self.assertEqual(
'bar',
template.render_complex(template.Template('{{ hello.foo }}',
self.hass),
{'hello': {'foo': 'bar'}}))
def test_passing_vars_as_dict(self):
"""Test passing variables as list."""
self.assertEqual(
"{'foo': 'bar'}",
template.render_complex(template.Template('{{ hello }}',
self.hass), {'hello': {'foo': 'bar'}}))
def test_render_with_possible_json_value_with_valid_json(self):
"""Render with possible JSON value with valid JSON."""
tpl = template.Template('{{ value_json.hello }}', self.hass)