core/tests/components/demo
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
..
__init__.py Move components to folders (#20774) 2019-02-05 19:31:15 -08:00
test_calendar.py Consolidate more platforms (#22308) 2019-03-23 20:22:35 -07:00
test_camera.py use isort to sort imports according to PEP8 for demo (#29630) 2019-12-08 22:29:27 +05:30
test_climate.py Add climate device triggers (#28544) 2019-11-07 16:28:45 +01:00
test_cover.py use isort to sort imports according to PEP8 for demo (#29630) 2019-12-08 22:29:27 +05:30
test_fan.py use isort to sort imports according to PEP8 for demo (#29630) 2019-12-08 22:29:27 +05:30
test_geo_location.py use isort to sort imports according to PEP8 for demo (#29630) 2019-12-08 22:29:27 +05:30
test_init.py use isort to sort imports according to PEP8 for demo (#29630) 2019-12-08 22:29:27 +05:30
test_light.py use isort to sort imports according to PEP8 for demo (#29630) 2019-12-08 22:29:27 +05:30
test_lock.py use isort to sort imports according to PEP8 for demo (#29630) 2019-12-08 22:29:27 +05:30
test_media_player.py Remove unnecessary string literal concatenations (#30360) 2020-01-02 21:17:10 +02:00
test_notify.py Add support for simultaneous runs of Script helper (#31937) 2020-02-24 14:56:00 -08:00
test_remote.py use isort to sort imports according to PEP8 for demo (#29630) 2019-12-08 22:29:27 +05:30
test_stt.py use isort to sort imports according to PEP8 for demo (#29630) 2019-12-08 22:29:27 +05:30
test_vacuum.py Entity Component to no longer generate automatic groups (#23789) 2020-01-07 17:30:53 +01:00
test_water_heater.py use isort to sort imports according to PEP8 for demo (#29630) 2019-12-08 22:29:27 +05:30