Fix not trying to disconnect cleanly on forced disconnect (#512)

This commit is contained in:
J. Nick Koston 2023-07-27 08:28:14 -05:00 committed by GitHub
parent 762d00faff
commit 48b56ad25c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -825,6 +825,19 @@ class APIConnection:
self._cleanup()
async def force_disconnect(self) -> None:
self._set_connection_state(ConnectionState.CLOSED)
"""Forcefully disconnect from the API."""
self._expected_disconnect = True
if self._is_socket_open and self._frame_helper:
# Still try to tell the esp to disconnect gracefully
# but don't wait for it to finish
try:
self.send_message(DisconnectRequest())
except APIConnectionError as err:
_LOGGER.error(
"%s: Failed to send (forced) disconnect request: %s",
self.log_name,
err,
)
self._set_connection_state(ConnectionState.CLOSED)
self._cleanup()