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 21:17:00 -05:00
committed by Paulus Schoutsen
parent be94e67ecc
commit d32c32608b
@@ -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",