From 81f6e67038ecec1b20c7937b73593bf702d145b7 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 5 Mar 2023 18:52:55 -1000 Subject: [PATCH] Fix disconnect message not being sent when disconnecting during hello phase (#396) --- aioesphomeapi/connection.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aioesphomeapi/connection.py b/aioesphomeapi/connection.py index b40742a..d530a5a 100644 --- a/aioesphomeapi/connection.py +++ b/aioesphomeapi/connection.py @@ -645,8 +645,11 @@ class APIConnection: await self.send_message_await_response(PingRequest(), PingResponse) async def disconnect(self) -> None: - if self._connection_state != ConnectionState.CONNECTED: - # already disconnected + if not self._is_socket_open or not self._frame_helper: + # We still want to send a disconnect request even + # if the hello phase isn't finished to ensure we + # the esp will clean up the connection as soon + # as possible. return self._expected_disconnect = True