mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
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:
parent
ff9568ad26
commit
b961b5037f
@ -70,8 +70,12 @@ def setup(hass, config):
|
|||||||
""" Execute a service call to script.<script name>. """
|
""" Execute a service call to script.<script name>. """
|
||||||
entity_id = ENTITY_ID_FORMAT.format(service.service)
|
entity_id = ENTITY_ID_FORMAT.format(service.service)
|
||||||
script = component.entities.get(entity_id)
|
script = component.entities.get(entity_id)
|
||||||
if script:
|
if not script:
|
||||||
script.turn_on()
|
return
|
||||||
|
if script.is_on:
|
||||||
|
_LOGGER.warning("Script %s already running.", entity_id)
|
||||||
|
return
|
||||||
|
script.turn_on()
|
||||||
|
|
||||||
for object_id, cfg in config[DOMAIN].items():
|
for object_id, cfg in config[DOMAIN].items():
|
||||||
if object_id != slugify(object_id):
|
if object_id != slugify(object_id):
|
||||||
|
@ -232,3 +232,40 @@ class TestScript(unittest.TestCase):
|
|||||||
self.assertFalse(script.is_on(self.hass, ENTITY_ID))
|
self.assertFalse(script.is_on(self.hass, ENTITY_ID))
|
||||||
|
|
||||||
self.assertEqual(0, len(calls))
|
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))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user