Initial script condition support (#1910)
This commit is contained in:
parent
953223b81b
commit
6354399d55
19 changed files with 656 additions and 427 deletions
|
@ -216,3 +216,36 @@ class TestScriptHelper(unittest.TestCase):
|
|||
assert not script_obj.is_running
|
||||
assert len(calls) == 2
|
||||
assert calls[-1].data['hello'] == 'universe'
|
||||
|
||||
def test_condition(self):
|
||||
"""Test if we can use conditions in a script."""
|
||||
event = 'test_event'
|
||||
events = []
|
||||
|
||||
def record_event(event):
|
||||
"""Add recorded event to set."""
|
||||
events.append(event)
|
||||
|
||||
self.hass.bus.listen(event, record_event)
|
||||
|
||||
self.hass.states.set('test.entity', 'hello')
|
||||
|
||||
script_obj = script.Script(self.hass, [
|
||||
{'event': event},
|
||||
{
|
||||
'condition': 'state',
|
||||
'entity_id': 'test.entity',
|
||||
'state': 'hello',
|
||||
},
|
||||
{'event': event},
|
||||
])
|
||||
|
||||
script_obj.run()
|
||||
self.hass.pool.block_till_done()
|
||||
assert len(events) == 2
|
||||
|
||||
self.hass.states.set('test.entity', 'goodbye')
|
||||
|
||||
script_obj.run()
|
||||
self.hass.pool.block_till_done()
|
||||
assert len(events) == 3
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue