mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix un-retrieved future in esphome ble client when library raises (#82537)
This commit is contained in:
parent
c30ce12c49
commit
18dd605a74
@ -265,11 +265,26 @@ class ESPHomeClient(BaseBleakClient):
|
|||||||
if not (scanner := async_scanner_by_source(self._hass, self._source)):
|
if not (scanner := async_scanner_by_source(self._hass, self._source)):
|
||||||
raise BleakError("Scanner disappeared for {self._source}")
|
raise BleakError("Scanner disappeared for {self._source}")
|
||||||
with scanner.connecting():
|
with scanner.connecting():
|
||||||
self._cancel_connection_state = await self._client.bluetooth_device_connect(
|
try:
|
||||||
self._address_as_int,
|
self._cancel_connection_state = (
|
||||||
_on_bluetooth_connection_state,
|
await self._client.bluetooth_device_connect(
|
||||||
timeout=timeout,
|
self._address_as_int,
|
||||||
)
|
_on_bluetooth_connection_state,
|
||||||
|
timeout=timeout,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except Exception: # pylint: disable=broad-except
|
||||||
|
with contextlib.suppress(BleakError):
|
||||||
|
# If the connect call throws an exception,
|
||||||
|
# we need to make sure we await the future
|
||||||
|
# to avoid a warning about an un-retrieved
|
||||||
|
# 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
|
||||||
await connected_future
|
await connected_future
|
||||||
await self.get_services(dangerous_use_bleak_cache=dangerous_use_bleak_cache)
|
await self.get_services(dangerous_use_bleak_cache=dangerous_use_bleak_cache)
|
||||||
self._disconnected_event = asyncio.Event()
|
self._disconnected_event = asyncio.Event()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user