Raise an exception when an esp proxy gets empty services during connection so callers know to retry (#83211)

This commit is contained in:
J. Nick Koston 2022-12-04 09:05:46 -10:00 committed by GitHub
parent 6499f5460a
commit c617e7da31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -317,7 +317,20 @@ class ESPHomeClient(BaseBleakClient):
connected_future.cancel()
raise
await connected_future
await self.get_services(dangerous_use_bleak_cache=dangerous_use_bleak_cache)
try:
await self.get_services(dangerous_use_bleak_cache=dangerous_use_bleak_cache)
except asyncio.CancelledError:
# On cancel we must still raise cancelled error
# to avoid blocking the cancellation even if the
# disconnect call fails.
with contextlib.suppress(Exception):
await self.disconnect()
raise
except Exception:
await self.disconnect()
raise
self._disconnected_event = asyncio.Event()
return True
@ -427,6 +440,12 @@ class ESPHomeClient(BaseBleakClient):
characteristic.handle,
)
)
if not esphome_services.services:
# If we got no services, we must have disconnected
# or something went wrong on the ESP32's BLE stack.
raise BleakError("Failed to get services from remote esp")
self.services = services
_LOGGER.debug(
"%s: %s - %s: Cached services saved",