Ensure onvif can still be unloaded if camera fails to unsubscribe (#91887)

This commit is contained in:
J. Nick Koston 2023-04-24 07:13:04 -05:00 committed by GitHub
parent c5d0c392a9
commit 6c024405a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)