mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Handle 404 for media/ptz/image onvif services to allow setup to proceed (#91875)
This commit is contained in:
parent
e4744199ce
commit
942a955a77
@ -11,7 +11,7 @@ from httpx import RequestError
|
|||||||
import onvif
|
import onvif
|
||||||
from onvif import ONVIFCamera
|
from onvif import ONVIFCamera
|
||||||
from onvif.exceptions import ONVIFError
|
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.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -39,6 +39,10 @@ from .const import (
|
|||||||
from .event import EventManager
|
from .event import EventManager
|
||||||
from .models import PTZ, Capabilities, DeviceInfo, Profile, Resolution, Video
|
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:
|
class ONVIFDevice:
|
||||||
"""Manages an ONVIF device."""
|
"""Manages an ONVIF device."""
|
||||||
@ -264,23 +268,23 @@ class ONVIFDevice:
|
|||||||
async def async_get_capabilities(self):
|
async def async_get_capabilities(self):
|
||||||
"""Obtain information about the available services on the device."""
|
"""Obtain information about the available services on the device."""
|
||||||
snapshot = False
|
snapshot = False
|
||||||
with suppress(ONVIFError, Fault, RequestError):
|
with suppress(*GET_CAPABILITIES_EXCEPTIONS):
|
||||||
media_service = self.device.create_media_service()
|
media_service = self.device.create_media_service()
|
||||||
media_capabilities = await media_service.GetServiceCapabilities()
|
media_capabilities = await media_service.GetServiceCapabilities()
|
||||||
snapshot = media_capabilities and media_capabilities.SnapshotUri
|
snapshot = media_capabilities and media_capabilities.SnapshotUri
|
||||||
|
|
||||||
ptz = False
|
ptz = False
|
||||||
with suppress(ONVIFError, Fault, RequestError):
|
with suppress(*GET_CAPABILITIES_EXCEPTIONS):
|
||||||
self.device.get_definition("ptz")
|
self.device.get_definition("ptz")
|
||||||
ptz = True
|
ptz = True
|
||||||
|
|
||||||
imaging = False
|
imaging = False
|
||||||
with suppress(ONVIFError, Fault, RequestError):
|
with suppress(*GET_CAPABILITIES_EXCEPTIONS):
|
||||||
self.device.create_imaging_service()
|
self.device.create_imaging_service()
|
||||||
imaging = True
|
imaging = True
|
||||||
|
|
||||||
events = False
|
events = False
|
||||||
with suppress(ONVIFError, Fault, RequestError, XMLParseError):
|
with suppress(*GET_CAPABILITIES_EXCEPTIONS, XMLParseError):
|
||||||
events = await self.events.async_start()
|
events = await self.events.async_start()
|
||||||
|
|
||||||
return Capabilities(snapshot, events, ptz, imaging)
|
return Capabilities(snapshot, events, ptz, imaging)
|
||||||
@ -330,7 +334,7 @@ class ONVIFDevice:
|
|||||||
ptz_service = self.device.create_ptz_service()
|
ptz_service = self.device.create_ptz_service()
|
||||||
presets = await ptz_service.GetPresets(profile.token)
|
presets = await ptz_service.GetPresets(profile.token)
|
||||||
profile.ptz.presets = [preset.token for preset in presets if preset]
|
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
|
# It's OK if Presets aren't supported
|
||||||
profile.ptz.presets = []
|
profile.ptz.presets = []
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user