Retry onvif setup when it is unexpectedly cancelled (#92313)

* Retry onvif setup when it is unexpectedly cancelled

fixes #92308

* Retry onvif setup when it is unexpectedly cancelled

fixes #92308
This commit is contained in:
J. Nick Koston
2023-05-01 22:55:08 +02:00
committed by Franck Nijhof
parent 2a5f5ea039
commit 8cbc69fc92
@@ -1,4 +1,5 @@
"""The ONVIF integration."""
import asyncio
import logging
from httpx import RequestError
@@ -57,6 +58,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
raise ConfigEntryNotReady(
f"Could not setup camera {device.device.host}:{device.device.port}: {err}"
) from err
except asyncio.CancelledError as err:
# After https://github.com/agronholm/anyio/issues/374 is resolved
# this may be able to be removed
await device.device.close()
raise ConfigEntryNotReady(f"Setup was unexpectedly canceled: {err}") from err
if not device.available:
raise ConfigEntryNotReady()