Wait_template - support for 'trigger.entity_id' and data_template values (#9807)
* *Added support for use of 'trigger.entity_id' and service->data_template->script in wait_template * * Fixed style violations * * Fixed regular expression (_RE_GET_POSSIBLE_ENTITIES) * * combined 'extract_entities' and 'extract_entities_with_variables' * fixed regular expression * * Added first test for extract_entities_with_variables * * Added Unittests (tests/helpers/test_template.py test_extract_entities_with_variables) * * Added Unittests (tests/helpers/test_script.py test_wait_template_variables) * * Added Unittests (tests/components/automation/test_template.py test_wait_template_with_trigger) * * Added Unittests (tests/components/automation/test_state.py test_wait_template_with_trigger) * * Added Unittests (tests/components/automation/test_numeric_state.py test_wait_template_with_trigger) * * Fixed style violations * * Fixed style violations * * Fixed style violations * * Fixed style violations * * Fixed style violations * * Fixed style violations * * Updated regular expression and delete whitespaces
This commit is contained in:
parent
c33b179fb8
commit
be5c0b2d92
8 changed files with 192 additions and 10 deletions
|
@ -345,6 +345,41 @@ class TestScriptHelper(unittest.TestCase):
|
|||
assert not script_obj.is_running
|
||||
assert len(events) == 1
|
||||
|
||||
def test_wait_template_variables(self):
|
||||
"""Test the wait template with variables."""
|
||||
event = 'test_event'
|
||||
events = []
|
||||
|
||||
@callback
|
||||
def record_event(event):
|
||||
"""Add recorded event to set."""
|
||||
events.append(event)
|
||||
|
||||
self.hass.bus.listen(event, record_event)
|
||||
|
||||
self.hass.states.set('switch.test', 'on')
|
||||
|
||||
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
||||
{'event': event},
|
||||
{'wait_template': "{{is_state(data, 'off')}}"},
|
||||
{'event': event}]))
|
||||
|
||||
script_obj.run({
|
||||
'data': 'switch.test'
|
||||
})
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert script_obj.is_running
|
||||
assert script_obj.can_cancel
|
||||
assert script_obj.last_action == event
|
||||
assert len(events) == 1
|
||||
|
||||
self.hass.states.set('switch.test', 'off')
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert not script_obj.is_running
|
||||
assert len(events) == 2
|
||||
|
||||
def test_passing_variables_to_script(self):
|
||||
"""Test if we can pass variables to script."""
|
||||
calls = []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue