mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user