RFC - Add a 3rd state to the HA shutdown sequence for writing… (#33358)

* 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
This commit is contained in:
David F. Mulcahey authored and GitHub committed 2020-03-30 10:18:39 -07:00
1 parent 01bf4daf37
commit bcd1eb952c
6 files changed
+27 -8

No files matched your search

+7 -2
View File
@@ -4,7 +4,10 @@ from datetime import datetime, timedelta
import logging
from typing import Any, Awaitable, Dict, List, Optional, Set, cast
from homeassistant.const import EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP
from homeassistant.const import (
EVENT_HOMEASSISTANT_FINAL_WRITE,
EVENT_HOMEASSISTANT_START,
)
from homeassistant.core import (
CoreState,
HomeAssistant,
@@ -184,7 +187,9 @@ class RestoreStateData:
async_track_time_interval(self.hass, _async_dump_states, STATE_DUMP_INTERVAL)
# 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_FINAL_WRITE, _async_dump_states
)
@callback
def async_restore_entity_added(self, entity_id: str) -> None:
+2 -2
View File
@@ -5,7 +5,7 @@ import logging
import os
from typing import Any, Callable, Dict, List, Optional, Type, Union
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
from homeassistant.const import EVENT_HOMEASSISTANT_FINAL_WRITE
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
from homeassistant.helpers.event import async_call_later
from homeassistant.loader import bind_hass
@@ -153,7 +153,7 @@ class Store:
"""Ensure that we write if we quit before delay has passed."""
if self._unsub_stop_listener is None:
self._unsub_stop_listener = self.hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_STOP, self._async_callback_stop_write
EVENT_HOMEASSISTANT_FINAL_WRITE, self._async_callback_stop_write
)
@callback