core/homeassistant
Phil Bruckner b2d7bc40dc
Add support for simultaneous runs of Script helper (#31937)
* Add tests for legacy Script helper behavior

* Add Script helper if_running and run_mode options

- if_running controls what happens if Script run while previous run
  has not completed. Can be:
  - error: Raise an exception
  - ignore: Return without doing anything (previous run continues as-is)
  - parallel: Start run in new task
  - restart: Stop previous run before starting new run
- run_mode controls when call to async_run will return. Can be:
  - background: Returns immediately
  - legacy: Implements previous behavior, which is to return when done,
            or when suspended by delay or wait_template
  - blocking: Returns when run has completed
- If neither is specified, default is run_mode=legacy (and if_running
  is not used.) Otherwise, defaults are if_running=parallel and
  run_mode=background. If run_mode is set to legacy then if_running must
  be None.
- Caller may supply a logger which will be used throughout instead of
  default module logger.
- Move Script running state into new helper classes, comprised of an
  abstract base class and two concrete clases, one for legacy behavior
  and one for new behavior.
- Remove some non-async methods, as well as call_from_config which has
  only been used in tests.
- Adjust tests accordingly.

* Change per review

- Change run_mode default from background to blocking.
- Make sure change listener is called, even when there's an unexpected
  exception.
- Make _ScriptRun.async_stop more graceful by using an asyncio.Event for
  signaling instead of simply cancelling Task.
- Subclass _ScriptRun for background & blocking behavior.

Also:

- Fix timeouts in _ScriptRun by converting timedeltas to float seconds.
- General cleanup.

* Change per review 2

- Don't propagate exceptions if call from user has already returned
  (i.e., for background runs or legacy runs that have suspended.)
- Allow user to specify if exceptions should be logged. They will still
  be logged regardless if exception is not propagated.
- Rename _start_script_delay and _start_wait_template_delay for
  clarity.
- Remove return value from Script.async_run.
- Fix missing await.
- Change call to self.is_running in Script.async_run to direct test of
  self._runs.

* Change per review 3 and add tests

- Remove Script.set_logger().
- Enhance existing tests to check all run modes.
- Add tests for new features.
- Fix a few minor bugs found by tests.
2020-02-24 14:56:00 -08:00
..
auth Replace cmp option with eq and order (#31423) 2020-02-02 20:28:52 -08:00
components Add support for simultaneous runs of Script helper (#31937) 2020-02-24 14:56:00 -08:00
generated Add initial version of Vilfo Router integration (#31177) 2020-02-12 19:11:15 +01:00
helpers Add support for simultaneous runs of Script helper (#31937) 2020-02-24 14:56:00 -08:00
scripts Speed up validate_entity_id (#32137) 2020-02-24 08:35:02 -08:00
util Use ciso8601 library to parse datetime faster (#32128) 2020-02-24 08:33:10 -08:00
__init__.py
__main__.py Add Safe Mode (#30723) 2020-01-14 13:03:02 -08:00
bootstrap.py Only check frontend for safe mode if frontend wanted to be loa… (#31969) 2020-02-19 15:56:46 +01:00
config.py Add www. to all documentation links (#32063) 2020-02-21 16:10:02 -08:00
config_entries.py Annotate more async functions correctly (#31802) 2020-02-14 10:00:22 -08:00
const.py Add and use time related constants (#32065) 2020-02-23 22:09:24 +02:00
core.py Speed up validate_entity_id (#32137) 2020-02-24 08:35:02 -08:00
data_entry_flow.py Fix typos found by codespell (#31243) 2020-01-31 08:33:00 -08:00
exceptions.py
loader.py Extend safe mode (#31927) 2020-02-18 11:52:38 -08:00
package_constraints.txt Use ciso8601 library to parse datetime faster (#32128) 2020-02-24 08:33:10 -08:00
requirements.py
setup.py print component import error to logfile (#30346) 2020-01-19 22:05:10 -08:00