From 942a955a77a39452bba40ddead9cf962e329c1af Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 22 Apr 2023 18:16:37 -0500 Subject: [PATCH] Handle 404 for media/ptz/image onvif services to allow setup to proceed (#91875) --- homeassistant/components/onvif/device.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/onvif/device.py b/homeassistant/components/onvif/device.py index 9eddd66ecd9..2ff80b639d2 100644 --- a/homeassistant/components/onvif/device.py +++ b/homeassistant/components/onvif/device.py @@ -11,7 +11,7 @@ from httpx import RequestError import onvif from onvif import ONVIFCamera from onvif.exceptions import ONVIFError -from zeep.exceptions import Fault, XMLParseError +from zeep.exceptions import Fault, TransportError, XMLParseError from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -39,6 +39,10 @@ from .const import ( from .event import EventManager from .models import PTZ, Capabilities, DeviceInfo, Profile, Resolution, Video +# Some cameras don't support the GetServiceCapabilities call +# and will return a 404 error which is caught by TransportError +GET_CAPABILITIES_EXCEPTIONS = (ONVIFError, Fault, RequestError, TransportError) + class ONVIFDevice: """Manages an ONVIF device.""" @@ -264,23 +268,23 @@ class ONVIFDevice: async def async_get_capabilities(self): """Obtain information about the available services on the device.""" snapshot = False - with suppress(ONVIFError, Fault, RequestError): + with suppress(*GET_CAPABILITIES_EXCEPTIONS): media_service = self.device.create_media_service() media_capabilities = await media_service.GetServiceCapabilities() snapshot = media_capabilities and media_capabilities.SnapshotUri ptz = False - with suppress(ONVIFError, Fault, RequestError): + with suppress(*GET_CAPABILITIES_EXCEPTIONS): self.device.get_definition("ptz") ptz = True imaging = False - with suppress(ONVIFError, Fault, RequestError): + with suppress(*GET_CAPABILITIES_EXCEPTIONS): self.device.create_imaging_service() imaging = True events = False - with suppress(ONVIFError, Fault, RequestError, XMLParseError): + with suppress(*GET_CAPABILITIES_EXCEPTIONS, XMLParseError): events = await self.events.async_start() return Capabilities(snapshot, events, ptz, imaging) @@ -330,7 +334,7 @@ class ONVIFDevice: ptz_service = self.device.create_ptz_service() presets = await ptz_service.GetPresets(profile.token) profile.ptz.presets = [preset.token for preset in presets if preset] - except (Fault, RequestError): + except GET_CAPABILITIES_EXCEPTIONS: # It's OK if Presets aren't supported profile.ptz.presets = []