Only turn on scripts that are not currently running.

Prevents an errant API call from advancing a currently executing delay
step before it should.
This commit is contained in:
Andrew Thigpen committed 2016-02-21 11:11:35 -06:00
1 parent ff9568ad26
commit b961b5037f
2 files changed
+43 -2

No files matched your search

+37
View File
@@ -232,3 +232,40 @@ class TestScript(unittest.TestCase):
self.assertFalse(script.is_on(self.hass, ENTITY_ID))
self.assertEqual(0, len(calls))
def test_turn_on_service(self):
"""
Verifies that the turn_on service for a script only turns on scripts
that are not currently running.
"""
event = 'test_event'
calls = []
def record_event(event):
calls.append(event)
self.hass.bus.listen(event, record_event)
self.assertTrue(script.setup(self.hass, {
'script': {
'test': {
'sequence': [{
'delay': {
'seconds': 5
}
}, {
'event': event,
}]
}
}
}))
script.turn_on(self.hass, ENTITY_ID)
self.hass.pool.block_till_done()
self.assertTrue(script.is_on(self.hass, ENTITY_ID))
self.assertEqual(0, len(calls))
# calling turn_on a second time should not advance the script
script.turn_on(self.hass, ENTITY_ID)
self.hass.pool.block_till_done()
self.assertEqual(0, len(calls))