Log delay and wait_template steps in scripts (#18448)
* Log delay and wait_template steps in scripts Help improve script debugging by logging delay and wait_template steps in scripts. * Update tests * Fix lint issue
This commit is contained in:
parent
089a2f4e71
commit
83b4e56978
2 changed files with 41 additions and 19 deletions
|
@ -120,6 +120,10 @@ class Script():
|
||||||
self.name, ex)
|
self.name, ex)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
self.last_action = action.get(
|
||||||
|
CONF_ALIAS, 'delay {}'.format(delay))
|
||||||
|
self._log("Executing step %s" % self.last_action)
|
||||||
|
|
||||||
unsub = async_track_point_in_utc_time(
|
unsub = async_track_point_in_utc_time(
|
||||||
self.hass, async_script_delay,
|
self.hass, async_script_delay,
|
||||||
date_util.utcnow() + delay
|
date_util.utcnow() + delay
|
||||||
|
@ -136,6 +140,9 @@ class Script():
|
||||||
wait_template = action[CONF_WAIT_TEMPLATE]
|
wait_template = action[CONF_WAIT_TEMPLATE]
|
||||||
wait_template.hass = self.hass
|
wait_template.hass = self.hass
|
||||||
|
|
||||||
|
self.last_action = action.get(CONF_ALIAS, 'wait template')
|
||||||
|
self._log("Executing step %s" % self.last_action)
|
||||||
|
|
||||||
# check if condition already okay
|
# check if condition already okay
|
||||||
if condition.async_template(
|
if condition.async_template(
|
||||||
self.hass, wait_template, variables):
|
self.hass, wait_template, variables):
|
||||||
|
|
|
@ -167,6 +167,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
event = 'test_event'
|
event = 'test_event'
|
||||||
events = []
|
events = []
|
||||||
context = Context()
|
context = Context()
|
||||||
|
delay_alias = 'delay step'
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def record_event(event):
|
def record_event(event):
|
||||||
|
@ -177,7 +178,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
|
|
||||||
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
||||||
{'event': event},
|
{'event': event},
|
||||||
{'delay': {'seconds': 5}},
|
{'delay': {'seconds': 5}, 'alias': delay_alias},
|
||||||
{'event': event}]))
|
{'event': event}]))
|
||||||
|
|
||||||
script_obj.run(context=context)
|
script_obj.run(context=context)
|
||||||
|
@ -185,7 +186,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
|
|
||||||
assert script_obj.is_running
|
assert script_obj.is_running
|
||||||
assert script_obj.can_cancel
|
assert script_obj.can_cancel
|
||||||
assert script_obj.last_action == event
|
assert script_obj.last_action == delay_alias
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
|
|
||||||
future = dt_util.utcnow() + timedelta(seconds=5)
|
future = dt_util.utcnow() + timedelta(seconds=5)
|
||||||
|
@ -201,6 +202,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
"""Test the delay as a template."""
|
"""Test the delay as a template."""
|
||||||
event = 'test_event'
|
event = 'test_event'
|
||||||
events = []
|
events = []
|
||||||
|
delay_alias = 'delay step'
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def record_event(event):
|
def record_event(event):
|
||||||
|
@ -211,7 +213,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
|
|
||||||
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
||||||
{'event': event},
|
{'event': event},
|
||||||
{'delay': '00:00:{{ 5 }}'},
|
{'delay': '00:00:{{ 5 }}', 'alias': delay_alias},
|
||||||
{'event': event}]))
|
{'event': event}]))
|
||||||
|
|
||||||
script_obj.run()
|
script_obj.run()
|
||||||
|
@ -219,7 +221,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
|
|
||||||
assert script_obj.is_running
|
assert script_obj.is_running
|
||||||
assert script_obj.can_cancel
|
assert script_obj.can_cancel
|
||||||
assert script_obj.last_action == event
|
assert script_obj.last_action == delay_alias
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
|
|
||||||
future = dt_util.utcnow() + timedelta(seconds=5)
|
future = dt_util.utcnow() + timedelta(seconds=5)
|
||||||
|
@ -259,6 +261,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
"""Test the delay with a working complex template."""
|
"""Test the delay with a working complex template."""
|
||||||
event = 'test_event'
|
event = 'test_event'
|
||||||
events = []
|
events = []
|
||||||
|
delay_alias = 'delay step'
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def record_event(event):
|
def record_event(event):
|
||||||
|
@ -270,8 +273,8 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
||||||
{'event': event},
|
{'event': event},
|
||||||
{'delay': {
|
{'delay': {
|
||||||
'seconds': '{{ 5 }}'
|
'seconds': '{{ 5 }}'},
|
||||||
}},
|
'alias': delay_alias},
|
||||||
{'event': event}]))
|
{'event': event}]))
|
||||||
|
|
||||||
script_obj.run()
|
script_obj.run()
|
||||||
|
@ -279,7 +282,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
|
|
||||||
assert script_obj.is_running
|
assert script_obj.is_running
|
||||||
assert script_obj.can_cancel
|
assert script_obj.can_cancel
|
||||||
assert script_obj.last_action == event
|
assert script_obj.last_action == delay_alias
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
|
|
||||||
future = dt_util.utcnow() + timedelta(seconds=5)
|
future = dt_util.utcnow() + timedelta(seconds=5)
|
||||||
|
@ -358,6 +361,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
event = 'test_event'
|
event = 'test_event'
|
||||||
events = []
|
events = []
|
||||||
context = Context()
|
context = Context()
|
||||||
|
wait_alias = 'wait step'
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def record_event(event):
|
def record_event(event):
|
||||||
|
@ -370,7 +374,8 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
|
|
||||||
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
||||||
{'event': event},
|
{'event': event},
|
||||||
{'wait_template': "{{states.switch.test.state == 'off'}}"},
|
{'wait_template': "{{states.switch.test.state == 'off'}}",
|
||||||
|
'alias': wait_alias},
|
||||||
{'event': event}]))
|
{'event': event}]))
|
||||||
|
|
||||||
script_obj.run(context=context)
|
script_obj.run(context=context)
|
||||||
|
@ -378,7 +383,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
|
|
||||||
assert script_obj.is_running
|
assert script_obj.is_running
|
||||||
assert script_obj.can_cancel
|
assert script_obj.can_cancel
|
||||||
assert script_obj.last_action == event
|
assert script_obj.last_action == wait_alias
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
|
|
||||||
self.hass.states.set('switch.test', 'off')
|
self.hass.states.set('switch.test', 'off')
|
||||||
|
@ -393,6 +398,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
"""Test the wait template cancel action."""
|
"""Test the wait template cancel action."""
|
||||||
event = 'test_event'
|
event = 'test_event'
|
||||||
events = []
|
events = []
|
||||||
|
wait_alias = 'wait step'
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def record_event(event):
|
def record_event(event):
|
||||||
|
@ -405,7 +411,8 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
|
|
||||||
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
||||||
{'event': event},
|
{'event': event},
|
||||||
{'wait_template': "{{states.switch.test.state == 'off'}}"},
|
{'wait_template': "{{states.switch.test.state == 'off'}}",
|
||||||
|
'alias': wait_alias},
|
||||||
{'event': event}]))
|
{'event': event}]))
|
||||||
|
|
||||||
script_obj.run()
|
script_obj.run()
|
||||||
|
@ -413,7 +420,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
|
|
||||||
assert script_obj.is_running
|
assert script_obj.is_running
|
||||||
assert script_obj.can_cancel
|
assert script_obj.can_cancel
|
||||||
assert script_obj.last_action == event
|
assert script_obj.last_action == wait_alias
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
|
|
||||||
script_obj.stop()
|
script_obj.stop()
|
||||||
|
@ -457,6 +464,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
"""Test the wait template, halt on timeout."""
|
"""Test the wait template, halt on timeout."""
|
||||||
event = 'test_event'
|
event = 'test_event'
|
||||||
events = []
|
events = []
|
||||||
|
wait_alias = 'wait step'
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def record_event(event):
|
def record_event(event):
|
||||||
|
@ -472,7 +480,8 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
{
|
{
|
||||||
'wait_template': "{{states.switch.test.state == 'off'}}",
|
'wait_template': "{{states.switch.test.state == 'off'}}",
|
||||||
'continue_on_timeout': False,
|
'continue_on_timeout': False,
|
||||||
'timeout': 5
|
'timeout': 5,
|
||||||
|
'alias': wait_alias
|
||||||
},
|
},
|
||||||
{'event': event}]))
|
{'event': event}]))
|
||||||
|
|
||||||
|
@ -481,7 +490,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
|
|
||||||
assert script_obj.is_running
|
assert script_obj.is_running
|
||||||
assert script_obj.can_cancel
|
assert script_obj.can_cancel
|
||||||
assert script_obj.last_action == event
|
assert script_obj.last_action == wait_alias
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
|
|
||||||
future = dt_util.utcnow() + timedelta(seconds=5)
|
future = dt_util.utcnow() + timedelta(seconds=5)
|
||||||
|
@ -495,6 +504,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
"""Test the wait template with continuing the script."""
|
"""Test the wait template with continuing the script."""
|
||||||
event = 'test_event'
|
event = 'test_event'
|
||||||
events = []
|
events = []
|
||||||
|
wait_alias = 'wait step'
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def record_event(event):
|
def record_event(event):
|
||||||
|
@ -510,7 +520,8 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
{
|
{
|
||||||
'wait_template': "{{states.switch.test.state == 'off'}}",
|
'wait_template': "{{states.switch.test.state == 'off'}}",
|
||||||
'timeout': 5,
|
'timeout': 5,
|
||||||
'continue_on_timeout': True
|
'continue_on_timeout': True,
|
||||||
|
'alias': wait_alias
|
||||||
},
|
},
|
||||||
{'event': event}]))
|
{'event': event}]))
|
||||||
|
|
||||||
|
@ -519,7 +530,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
|
|
||||||
assert script_obj.is_running
|
assert script_obj.is_running
|
||||||
assert script_obj.can_cancel
|
assert script_obj.can_cancel
|
||||||
assert script_obj.last_action == event
|
assert script_obj.last_action == wait_alias
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
|
|
||||||
future = dt_util.utcnow() + timedelta(seconds=5)
|
future = dt_util.utcnow() + timedelta(seconds=5)
|
||||||
|
@ -533,6 +544,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
"""Test the wait template with default contiune."""
|
"""Test the wait template with default contiune."""
|
||||||
event = 'test_event'
|
event = 'test_event'
|
||||||
events = []
|
events = []
|
||||||
|
wait_alias = 'wait step'
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def record_event(event):
|
def record_event(event):
|
||||||
|
@ -547,7 +559,8 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
{'event': event},
|
{'event': event},
|
||||||
{
|
{
|
||||||
'wait_template': "{{states.switch.test.state == 'off'}}",
|
'wait_template': "{{states.switch.test.state == 'off'}}",
|
||||||
'timeout': 5
|
'timeout': 5,
|
||||||
|
'alias': wait_alias
|
||||||
},
|
},
|
||||||
{'event': event}]))
|
{'event': event}]))
|
||||||
|
|
||||||
|
@ -556,7 +569,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
|
|
||||||
assert script_obj.is_running
|
assert script_obj.is_running
|
||||||
assert script_obj.can_cancel
|
assert script_obj.can_cancel
|
||||||
assert script_obj.last_action == event
|
assert script_obj.last_action == wait_alias
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
|
|
||||||
future = dt_util.utcnow() + timedelta(seconds=5)
|
future = dt_util.utcnow() + timedelta(seconds=5)
|
||||||
|
@ -570,6 +583,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
"""Test the wait template with variables."""
|
"""Test the wait template with variables."""
|
||||||
event = 'test_event'
|
event = 'test_event'
|
||||||
events = []
|
events = []
|
||||||
|
wait_alias = 'wait step'
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def record_event(event):
|
def record_event(event):
|
||||||
|
@ -582,7 +596,8 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
|
|
||||||
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
|
||||||
{'event': event},
|
{'event': event},
|
||||||
{'wait_template': "{{is_state(data, 'off')}}"},
|
{'wait_template': "{{is_state(data, 'off')}}",
|
||||||
|
'alias': wait_alias},
|
||||||
{'event': event}]))
|
{'event': event}]))
|
||||||
|
|
||||||
script_obj.run({
|
script_obj.run({
|
||||||
|
@ -592,7 +607,7 @@ class TestScriptHelper(unittest.TestCase):
|
||||||
|
|
||||||
assert script_obj.is_running
|
assert script_obj.is_running
|
||||||
assert script_obj.can_cancel
|
assert script_obj.can_cancel
|
||||||
assert script_obj.last_action == event
|
assert script_obj.last_action == wait_alias
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
|
|
||||||
self.hass.states.set('switch.test', 'off')
|
self.hass.states.set('switch.test', 'off')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue