Add automation options for parallel action runs#31740
Add automation options for parallel action runs#31740pnbruckner wants to merge 1 commit intohome-assistant:devfrom
Conversation
|
Hey there @home-assistant/core, mind taking a look at this pull request as its been labeled with a integration ( |
|
Hey there @home-assistant/core, mind taking a look at this pull request as its been labeled with a integration ( |
|
Since helper.script was reorganized it can be a bit difficult to review here on github. Also, I've been thinking that I should have put the new _ScriptRun class inside the Script class. And if I do it right it should make the differences much easier to read & understand. I'll start working on that next and push a new commit if it does indeed help. |
…n runs - Add optional automation config parameter parallel_action. Options and default are defined in Script helper class. - Move async_log_exception functionality entirely inside Script class. - Automation uses Script's last_triggered attribute. - Enhance Script class to properly support simultaneous parallel runs regardless of whether the script sequence contains delays or wait_templates. - Four options are available for what happens if script is run while it is already running: allow, error, restart & skip. - All run context is moved into a new helper class _ScriptRun. - Only update last_triggered when Script first run (i.e., not when resumed after delay or wait_template.) - Fix bug where wait_template listener is not canceled when timeout expires. - Update tests.
a87fe4f to
88bfb2d
Compare
|
Ok force pushed a new commit. This one should be easier to review. Still, you'll probably be better off using a better diff tool (for helpers/script.py) than github. lol |
This comment has been minimized.
This comment has been minimized.
|
Working on adding more tests for helpers/script.py. |
|
Closing for now. Will submit a new PR with the first, smaller set of changes to helpers/script.py & its tests hopefully before too long. |
|
When you open any of the new PRs, please request my review and I will expedite them. |
|
Thanks, will do. I haven't forgotten or given up. Still working on it. I hope to have the first one in the next few days. I've already written a few new tests to make sure I get the legacy mode stuff right. |
Breaking change
Previously if the action section of an automation contained a delay or wait_template step, and a trigger fires while the automation is still in one of these steps from a previous trigger event, the step would be aborted and the action would continue with the next step. This was apparently unintentional behavior and many people have been surprised by it, and have had to work around it.
This change fixes that behavior by allowing the user to specify what should happen when the automation is triggered while it is still running its actions from a previous trigger event. The default behavior in the scenario described above will be to stop the previous run and start the action sequence over from the beginning. Although this is probably what most people would have expected, it can break existing automations that depend on the current odd behavior.
Proposed change
Add a new, optional configuration parameter for automations, namely
parallel_action, which will control what happens when the automation is triggered while the action sequence is still running from a previous trigger event. There are four options:allow-- The action sequence will be run in parallel with the previous run. This is the default if the action sequence does not contain adelayorwait_template.error-- The trigger will cause an ERROR.restart-- The previous run will be cancelled before a new run is started. This is the default if the action sequence does containdelayorwait_template.skip-- The trigger will be ignored and the previous run will continue unaltered.Type of change
Example entry for
configuration.yaml:Additional information
Detailed list of changes
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale: