Be flexible in what we accept for script.delay configuration. (#1738)

Accept delay configuration even when someone forgets to indent the time

specification.



Also removed 'weeks' and 'microseconds' from acceptable delay values.

There is a new homeassistant release every 2 weeks and running scripts

are not persisting across restarts. And there is still the option of

using (weeks*7) days if the long delay is really necessary.



And if someone really depends on microsecond delay precision we are

unlikely to be able to provide this accuracy, even milliseconds is

suspect for that matter but will at least allow us to specify some

subsecond delay.
This commit is contained in:
Jan Harkes authored and Paulus Schoutsen committed 2016-04-07 12:19:28 -07:00
1 parent 5b17f629ad
commit 29c30861bf
3 files changed
+66 -15

No files matched your search

+39
View File
@@ -206,6 +206,45 @@ class TestScript(unittest.TestCase):
self.assertEqual(2, len(calls))
def test_alt_delay(self):
"""Test alternative delay config format."""
event = 'test_event'
calls = []
def record_event(event):
"""Add recorded event to set."""
calls.append(event)
self.hass.bus.listen(event, record_event)
assert _setup_component(self.hass, 'script', {
'script': {
'test': {
'sequence': [{
'event': event,
}, {
'delay': None,
'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(1, len(calls))
future = dt_util.utcnow() + timedelta(seconds=5)
fire_time_changed(self.hass, future)
self.hass.pool.block_till_done()
self.assertFalse(script.is_on(self.hass, ENTITY_ID))
self.assertEqual(2, len(calls))
def test_cancel_while_delay(self):
"""Test the cancelling while the delay is present."""
event = 'test_event'