Avoid writing state to all esphome entities at shutdown (#90555)

This commit is contained in:
J. Nick Koston 2023-03-31 06:23:05 -10:00 committed by Paulus Schoutsen
parent 6884b0a421
commit 5e903e04cf

View File

@ -349,6 +349,11 @@ async def async_setup_entry( # noqa: C901
# the next state update of that type when the device reconnects
for state_keys in entry_data.state.values():
state_keys.clear()
if not hass.is_stopping:
# Avoid marking every esphome entity as unavailable on shutdown
# since it generates a lot of state changed events and database
# writes when we already know we're shutting down and the state
# will be cleared anyway.
entry_data.async_update_device_state(hass)
async def on_connect_error(err: Exception) -> None: