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:
parent
0e1cc05189
commit
48619c9d7c
6 changed files with 101 additions and 19 deletions
|
@ -56,6 +56,39 @@ class TestScriptHelper(unittest.TestCase):
|
|||
assert calls[0].data.get('hello') == 'world'
|
||||
assert not script_obj.can_cancel
|
||||
|
||||
def test_firing_event_template(self):
|
||||
"""Test the firing of events."""
|
||||
event = 'test_event'
|
||||
calls = []
|
||||
|
||||
@callback
|
||||
def record_event(event):
|
||||
"""Add recorded event to set."""
|
||||
calls.append(event)
|
||||
|
||||
self.hass.bus.listen(event, record_event)
|
||||
|
||||
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA({
|
||||
'event': event,
|
||||
'event_data_template': {
|
||||
'hello': """
|
||||
{% if is_world == 'yes' %}
|
||||
world
|
||||
{% else %}
|
||||
not world
|
||||
{% endif %}
|
||||
"""
|
||||
}
|
||||
}))
|
||||
|
||||
script_obj.run({'is_world': 'yes'})
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data.get('hello') == 'world'
|
||||
assert not script_obj.can_cancel
|
||||
|
||||
def test_calling_service(self):
|
||||
"""Test the calling of a service."""
|
||||
calls = []
|
||||
|
@ -99,14 +132,14 @@ class TestScriptHelper(unittest.TestCase):
|
|||
{% endif %}""",
|
||||
'data_template': {
|
||||
'hello': """
|
||||
{% if True %}
|
||||
{% if is_world == 'yes' %}
|
||||
world
|
||||
{% else %}
|
||||
Not world
|
||||
not world
|
||||
{% endif %}
|
||||
"""
|
||||
}
|
||||
})
|
||||
}, {'is_world': 'yes'})
|
||||
|
||||
self.hass.block_till_done()
|
||||
|
||||
|
@ -147,7 +180,7 @@ class TestScriptHelper(unittest.TestCase):
|
|||
|
||||
def test_delay_template(self):
|
||||
"""Test the delay as a template."""
|
||||
event = 'test_evnt'
|
||||
event = 'test_event'
|
||||
events = []
|
||||
|
||||
@callback
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue