From 30dd8b9f3a1d327af905bb1cd34434110734b445 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 30 Apr 2023 22:12:01 -0500 Subject: [PATCH] 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 --- homeassistant/components/onvif/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/homeassistant/components/onvif/__init__.py b/homeassistant/components/onvif/__init__.py index ec894befaea..2c96b79cbeb 100644 --- a/homeassistant/components/onvif/__init__.py +++ b/homeassistant/components/onvif/__init__.py @@ -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()