Ensure esphome connected future is awaited when connecting is canceled (#90329)

This commit is contained in:
J. Nick Koston 2023-03-26 12:30:00 -10:00 committed by GitHub
parent a733ca96a2
commit a7c796a2f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -322,7 +322,17 @@ class ESPHomeClient(BaseBleakClient):
address_type=self._address_type,
)
)
except asyncio.CancelledError:
if connected_future.done():
with contextlib.suppress(BleakError):
# If we are cancelled while connecting,
# we need to make sure we await the future
# to avoid a warning about an un-retrieved
# exception.
await connected_future
raise
except Exception:
if connected_future.done():
with contextlib.suppress(BleakError):
# If the connect call throws an exception,
# we need to make sure we await the future
@ -330,7 +340,6 @@ class ESPHomeClient(BaseBleakClient):
# exception since we prefer to raise the
# exception from the connect call as it
# will be more descriptive.
if connected_future.done():
await connected_future
connected_future.cancel()
raise