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 GitHub
parent 149e610bca
commit c566303edb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -349,7 +349,12 @@ 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()
entry_data.async_update_device_state(hass)
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:
"""Start reauth flow if appropriate connect error type."""