* Don't write storage to disk while stopping
* rework change
* lint
* remove delay save and schedule final write at stop
* update tests
* fix test component using private methods
* cleanup
* always listen
* use stop in restore state again
* whitelist JSON exceptions for later
* review comment
* make zwave tests use mock storage
* replace asyncio.wait with asyncio.gather since wait ignores exceptions
fix for test_entity_platform so it expects the exception
* changed to log on failed domains
* discovered that this fix actually removes other uncaught exceptions
* fix in the list of ignored exceptions
* replaced a few ignores on dyson tests that work locally but fail in the CI
* two more tests that are failing on the CI and not locally
* removed assertion on multiple entries with same unique_id - replaced with log and return
reverted test_entity_platform to its original since now there is no exception thrown
* entered all the dyson tests. they all pass locally and probabilistically fail in the CI
* removed unnecessary str() for exception
* added log message for duplicate entity_id / unique_id
* removed log in case of False return value
* added exc_info
* change the use of exc_info
* add third stage to hass shutdown
* use 3rd stage in storage
* update core state
* add writing data to multi stop ignore
* update core test
* review comment
* update name based on feedback
* 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
* Fix scheduled update time-drift in data update coordinator
As next schedule is calculated **after** the update is done,
setting now + update_interval makes 1 second drift in practice,
as the tick is 1Hz.
* Floor the utcnow timestamp
to remove sub-second error precision, and generate constant frequency updates
as long as the update takes < 1s.
* 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.
* Allow managing Lovelace storage dashboards
* Make sure we do not allow duplicate url paths
* Allow setting sidebar to None
* Fix tests
* Delete storage file on delete
* List all dashboards
* [recorder] Use orjson to parse json faster
* Remove from http manifest
* Bump to orjson 2.5.1
* Empty commit to trigger CI
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
* 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.