* Merge action and condition traces
* Update __init__.py
* Add typing to AutomationTrace
* Make trace_get prepare a new trace by default
* Correct typing of trace_cv
* Fix tests
* Initial prototype of automation tracing
* Small fixes
* Lint
* Move trace helpers to its own file
* Improve trace for state and numeric_state conditions
* Tweaks + apply suggestions from code review
* Index traces by automation_id, trace while script is running
* Refactor condition tracing
* Improve WS API to get traces for single automation
* Add tests
* Fix imports
* Fix imports
* Address review comments
* Cap logging of loops
* Remove unused ContextVar action_config
* Unused pylint suppression cleanups
* Remove outdated pylint bug references
* Add flake8-noqa config and note to run it every now and then
* Add codes to noqa's
* Unused noqa cleanups
* Add support for limited templates (no HASS access)
* Pass variables to automation triggers
* Support templates in MQTT triggers
* Spelling
* Handle trigger referenced by variables
* Raise on unsupported function in limited templates
* Validate MQTT trigger schema in MQTT device trigger
* Add trigger_variables to automation config schema
* Don't print stacktrace when setting up trigger throws
* Make pylint happy
* Add trigger_variables to variables
* Add debug prints, document limited template
* Add tests
* Validate MQTT trigger topic early when possible
* Improve valid_subscribe_topic_template
* Add support for multiple time triggers in automations
* Attach with single callback
* Patch time in tests
* Improve test coverage
* Adjusting my facepalm moment
for scenarios of enabling/disabling (~ creating/removing) entities,
so it does not trigger in removal if a `to: xxx` is defined, and also
does not trigger in creation if a `from: xxx` is present.
* Cleanup async_track_state_change and augment docstrings.
Skip from_state and to_state matching in
async_track_state_change when they are None
Optimize the state change listener for the most
common use case: no to_state and from_state
matching.
* Update benchmark to be more realistic (previously we assumed only one entity was present in the whole instance)
* Add more tests to ensure behavior is preserved
* Ensure new behavior matches test
* remove MATCH_ALL from zone automation since its the default anyways
* Might as well use async_track_state_change_event instead since MATCH_ALL is removed
Calling async_track_state_change_event directly
is faster than async_track_state_change (see #37251) and has
slightly lower latency triggering state updates
* Add yamllint (in pre-commit and CI)
* Fix linting for all YAML files
* Bump and add it to requirements
* Fix gen_requirements for pre-commit, remove 'v' from version
* Fix state_automation_listener when new state is None (fix#32984)
* Listen to EVENT_STATE_CHANGED instead of using async_track_state_change
and use the event context on automation trigger.
* Share `process_state_match` with helpers/event
* Add test for state change automation on entity removal
* 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.
* Use f-strings in integrations starting with A
* Use f-strings in tests for integrations starting with A
* Fix pylint by renaming variable
* Fix nested for loop in f-string for aprs device_tracker
* Break long lines into multiple short lines
* Break long lines into multiple short lines v2
* Add support for MQTT device triggers
* Fix test, tweaks
* Improve test coverage
* Address review comments, improve tests
* Tidy up exception handling
* Fix abbreviations
* Rewrite to handle update of attached triggers
* Update abbreviation test
* Refactor according to review comments
* Refactor according to review comments
* Improve trigger removal
* Further refactoring