Move ESPHome disconnects to the close event (#113652)

This commit is contained in:
J. Nick Koston 2024-03-17 08:15:28 -10:00 committed by GitHub
parent 412fd3dc05
commit dbbd6fff01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 2 deletions

View File

@ -30,7 +30,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_DEVICE_ID,
CONF_MODE,
EVENT_HOMEASSISTANT_STOP,
EVENT_HOMEASSISTANT_CLOSE,
EVENT_LOGGING_CHANGED,
)
from homeassistant.core import Event, HomeAssistant, ServiceCall, State, callback
@ -542,9 +542,12 @@ class ESPHomeManager:
# the callback twice when shutting down Home Assistant.
# "Unable to remove unknown listener
# <function EventBus.async_listen_once.<locals>.onetime_listener>"
# We only close the connection at the last possible moment
# when the CLOSE event is fired so anything using a Bluetooth
# proxy has a chance to shut down properly.
entry_data.cleanup_callbacks.append(
hass.bus.async_listen(
EVENT_HOMEASSISTANT_STOP, self.on_stop, run_immediately=True
EVENT_HOMEASSISTANT_CLOSE, self.on_stop, run_immediately=True
)
)
entry_data.cleanup_callbacks.append(