Ensure restore state is not written after the stop event (#49329)
If everything lined up, the states could be written while Home Assistant is shutting down after the stop event because the interval tracker was not canceled on the stop event.
This commit is contained in:
parent
41ed1f818c
commit
f96a6e878f
2 changed files with 60 additions and 4 deletions
|
@ -177,10 +177,18 @@ class RestoreStateData:
|
|||
self.hass.async_create_task(_async_dump_states())
|
||||
|
||||
# Dump states periodically
|
||||
async_track_time_interval(self.hass, _async_dump_states, STATE_DUMP_INTERVAL)
|
||||
cancel_interval = async_track_time_interval(
|
||||
self.hass, _async_dump_states, STATE_DUMP_INTERVAL
|
||||
)
|
||||
|
||||
async def _async_dump_states_at_stop(*_: Any) -> None:
|
||||
cancel_interval()
|
||||
await self.async_dump_states()
|
||||
|
||||
# Dump states when stopping hass
|
||||
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_dump_states)
|
||||
self.hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_STOP, _async_dump_states_at_stop
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_restore_entity_added(self, entity_id: str) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue