🏡 Open source home automation that puts local control and privacy first.
Go to file
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
.devcontainer
.github Activate Stale bot for PR's (#31837) 2020-02-17 00:22:51 +01:00
.vscode
docs
homeassistant Add support for simultaneous runs of Script helper (#31937) 2020-02-24 14:56:00 -08:00
script Properly define depenency for Scrape integration on Rest integ… (#32136) 2020-02-24 00:03:33 -08:00
tests Add support for simultaneous runs of Script helper (#31937) 2020-02-24 14:56:00 -08:00
.coveragerc Add platform Ezviz (#30378) 2020-02-24 10:39:55 +01:00
.dockerignore
.gitattributes
.gitignore
.ignore
.pre-commit-config.yaml Prevent committing to dev/master/rc directly (#32029) 2020-02-20 09:34:30 -08:00
.readthedocs.yml
.travis.yml
CLA.md
CODEOWNERS Add platform Ezviz (#30378) 2020-02-24 10:39:55 +01:00
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile.dev
LICENSE.md
MANIFEST.in
README.rst
azure-pipelines-ci.yml Run mypy through a pyenv/virtualenv enabler wrapper script (#30922) 2020-02-01 07:12:46 -08:00
azure-pipelines-release.yml Fix typos found by codespell (#31243) 2020-01-31 08:33:00 -08:00
azure-pipelines-translation.yml
azure-pipelines-wheels.yml
codecov.yml Update codecov.yml 2020-02-15 13:06:08 -08:00
pylintrc Use ciso8601 library to parse datetime faster (#32128) 2020-02-24 08:33:10 -08:00
pyproject.toml
requirements_all.txt Upgrade qnapstats to 0.3.0 (#32148) 2020-02-24 22:46:07 +01:00
requirements_docs.txt
requirements_test.txt Upgrade pre-commit to 2.1.0 (#31962) 2020-02-18 13:25:26 -08:00
requirements_test_all.txt Refactor homekit_controller to be fully asynchronous (#32111) 2020-02-24 10:55:33 +01:00
requirements_test_pre_commit.txt deCONZ - Services normalize bridge id (#31378) 2020-02-01 18:11:05 +01:00
setup.cfg
setup.py Use ciso8601 library to parse datetime faster (#32128) 2020-02-24 08:33:10 -08:00
tox.ini Run mypy through a pyenv/virtualenv enabler wrapper script (#30922) 2020-02-01 07:12:46 -08:00

README.rst

Home Assistant |Chat Status|
=================================================================================

Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server.

Check out `home-assistant.io <https://home-assistant.io>`__ for `a
demo <https://home-assistant.io/demo/>`__, `installation instructions <https://home-assistant.io/getting-started/>`__,
`tutorials <https://home-assistant.io/getting-started/automation-2/>`__ and `documentation <https://home-assistant.io/docs/>`__.

|screenshot-states|

Featured integrations
---------------------

|screenshot-components|

The system is built using a modular approach so support for other devices or actions can be implemented easily. See also the `section on architecture <https://developers.home-assistant.io/docs/en/architecture_index.html>`__ and the `section on creating your own
components <https://developers.home-assistant.io/docs/en/creating_component_index.html>`__.

If you run into issues while using Home Assistant or during development
of a component, check the `Home Assistant help section <https://home-assistant.io/help/>`__ of our website for further help and information.

.. |Chat Status| image:: https://img.shields.io/discord/330944238910963714.svg
   :target: https://discord.gg/c5DvZ4e
.. |screenshot-states| image:: https://raw.github.com/home-assistant/home-assistant/master/docs/screenshots.png
   :target: https://home-assistant.io/demo/
.. |screenshot-components| image:: https://raw.github.com/home-assistant/home-assistant/dev/docs/screenshot-components.png
   :target: https://home-assistant.io/integrations/