* Add limit parameter to service call methods
* Break out prep part of async_call_from_config for use elsewhere
* Minor cleanup
* Fix improper use of asyncio.wait
* Fix state update
Call change listener immediately if its a callback
* Fix exception handling and logging
* Merge Script helper if_running/run_mode parameters into script_mode
- Remove background/blocking _ScriptRun subclasses which are no longer needed.
* Add queued script mode
* Disable timeout when making fully blocking script call
* Don't call change listener when restarting script
This makes restart mode behavior consistent with parallel & queue modes.
* Changes per review
- Call all script services (except script.turn_off) with no time limit.
- Fix handling of lock in _QueuedScriptRun and add comments to make it
clearer how this code works.
* Changes per review 2
- Move cancel shielding "up" from _ScriptRun.async_run to Script.async_run
(and apply to new style scripts only.) This makes sure Script class also
properly handles cancellation which it wasn't doing before.
- In _ScriptRun._async_call_service_step, instead of using script.turn_off
service, just cancel service call and let it handle the cancellation
accordingly.
* Fix bugs
- Add missing call to change listener in Script.async_run
in cancelled path.
- Cancel service task if ServiceRegistry.async_call cancelled.
* Revert last changes to ServiceRegistry.async_call
* Minor Script helper fixes & test improvements
- Don't log asyncio.CancelledError exceptions.
- Make change_listener a public attribute.
- Test overhaul
- Parametrize tests.
- Use common test functions.
- Mock timeout so tests don't need to wait for real time to elapse.
- Add common function for waiting for script action step.
* 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.
* Type check all helpers, add inline exclusions for work in progress
* Remove unused Script._template_cache
* Add some missing type hints
* Remove unneeded type: ignore
* Type hint fixes
* Mypy assistance tweaks
* Don't look for None in deprecated config "at most once" check
* Avoid None name slugify attempt when generating entity id
* Avoid None state store attempt on entity remove
* 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
* Adding new feature to allow a wait template to run the remainer of the script on timeout
* Styling changes
* Fixing file permissions, adding test for new code
* changed variable name, refactored script to pass information into async_set_timeout
* Changing the default behaviour to continue to run the script after timeout
* Upgrade pylint to 1.8.1
* Fix no-else-return
* Fix bad-whitespace
* Fix too-many-nested-blocks
* Fix raising-format-tuple
See https://github.com/PyCQA/pylint/blob/master/doc/whatsnew/1.8.rst
* Fix len-as-condition
* Fix logging-not-lazy
Not sure about that TEMP_CELSIUS though, but internally it's probably just like if you concatenated any other (variable) string
* Fix stop-iteration-return
* Fix useless-super-delegation
* Fix trailing-comma-tuple
Both of these seem to simply be bugs:
* Nest: The value of self._humidity never seems to be used anywhere
* Dovado: The called API method seems to expect a "normal" number
* Fix redefined-argument-from-local
* Fix consider-using-enumerate
* Fix wrong-import-order
* Fix arguments-differ
* Fix missed no-else-return
* Fix no-member and related
* Fix signatures-differ
* Revert "Upgrade pylint to 1.8.1"
This reverts commit af78aa00f125a7d34add97b9d50c14db48412211.
* Fix arguments-differ
* except for device_tracker
* Cleanup
* Fix test using positional argument
* Fix line too long
I forgot to run flake8 - shame on me... 🙃
* Fix bad-option-value for 1.6.5
* Fix arguments-differ for device_tracker
* Upgrade pylint to 1.8.2
* 👕 Fix missed no-member
* Implemented event_data_template
* The hound does not like my indentation
* Added passed variables to tests for event and svc template calls
* Moved recursive function to template.py
* Update template.py
* Update template.py
* Cleaned up service.py and fixed unit tests
* Blank lines
* Removed stray logger statement
* Blank lines again
* Cache condition in helpers.Script
The caching is a simple in-memory, per-instance dictionary.
We use __str__ to format cache keys.
This naive implementation has some disadvantages (e.g., we won't be able
to cache two conditions that contain references to
distinct-but-equivalent object instances and we don't have any control
over the size of the condition cache), but for most simple use-cases the
approach should be good enough.
Resolves#3629
* Fix docstring style
* Template platforms: create_task instead of yield from
* Automation: less yielding, more create_tasking
* Helpers.script: less yielding, more create_tasking
* Deflake logbook test
* Deflake automation reload config test
* MQTT: Use async_add_job and threaded_listener_factory
* Deflake other logbook test
* lint
* Add test for automation trigger service
* MQTT client can be called from within async