From 6c024405a6049d91033eecd1e1e64696a3ae74fc Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 24 Apr 2023 07:13:04 -0500 Subject: [PATCH] Ensure onvif can still be unloaded if camera fails to unsubscribe (#91887) --- homeassistant/components/onvif/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/onvif/__init__.py b/homeassistant/components/onvif/__init__.py index 545ebbed799..6fec535b369 100644 --- a/homeassistant/components/onvif/__init__.py +++ b/homeassistant/components/onvif/__init__.py @@ -1,7 +1,9 @@ """The ONVIF integration.""" +import logging + from httpx import RequestError from onvif.exceptions import ONVIFAuthError, ONVIFError, ONVIFTimeoutError -from zeep.exceptions import Fault +from zeep.exceptions import Fault, TransportError from homeassistant.components.ffmpeg import CONF_EXTRA_ARGUMENTS from homeassistant.components.stream import CONF_RTSP_TRANSPORT, RTSP_TRANSPORTS @@ -18,6 +20,8 @@ from homeassistant.exceptions import ConfigEntryNotReady from .const import CONF_SNAPSHOT_AUTH, DEFAULT_ARGUMENTS, DOMAIN from .device import ONVIFDevice +LOGGER = logging.getLogger(__name__) + async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up ONVIF from a config entry.""" @@ -79,7 +83,10 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: device: ONVIFDevice = hass.data[DOMAIN][entry.unique_id] if device.capabilities.events and device.events.started: - await device.events.async_stop() + try: + await device.events.async_stop() + except (ONVIFError, Fault, RequestError, TransportError): + LOGGER.warning("Error while stopping events: %s", device.name) return await hass.config_entries.async_unload_platforms(entry, device.platforms)