fix mjpeg issue along with some cameras not returning event capabilities properly (#35885)

pull/35907/head
Jason Hunter 2020-05-20 21:26:27 -04:00 committed by Pascal Vizeli
parent c7008eb761
commit ae66f4250c
2 changed files with 12 additions and 12 deletions

View File

@ -106,11 +106,6 @@ class ONVIFCameraEntity(ONVIFBaseEntity, Camera):
async def stream_source(self):
"""Return the stream source."""
if self._stream_uri is None:
uri_no_auth = await self.device.async_get_stream_uri(self.profile)
self._stream_uri = uri_no_auth.replace(
"rtsp://", f"rtsp://{self.device.username}:{self.device.password}@", 1
)
return self._stream_uri
async def async_camera_image(self):
@ -118,11 +113,6 @@ class ONVIFCameraEntity(ONVIFBaseEntity, Camera):
image = None
if self.device.capabilities.snapshot:
if self._snapshot_uri is None:
self._snapshot_uri = await self.device.async_get_snapshot_uri(
self.profile
)
auth = None
if self.device.username and self.device.password:
auth = HTTPDigestAuth(self.device.username, self.device.password)
@ -181,6 +171,16 @@ class ONVIFCameraEntity(ONVIFBaseEntity, Camera):
finally:
await stream.close()
async def async_added_to_hass(self):
"""Run when entity about to be added to hass."""
uri_no_auth = await self.device.async_get_stream_uri(self.profile)
self._stream_uri = uri_no_auth.replace(
"rtsp://", f"rtsp://{self.device.username}:{self.device.password}@", 1
)
if self.device.capabilities.snapshot:
self._snapshot_uri = await self.device.async_get_snapshot_uri(self.profile)
async def async_perform_ptz(
self,
distance,

View File

@ -223,7 +223,7 @@ class ONVIFDevice:
try:
media_service = self.device.create_media_service()
media_capabilities = await media_service.GetServiceCapabilities()
snapshot = media_capabilities.SnapshotUri
snapshot = media_capabilities and media_capabilities.SnapshotUri
except (ONVIFError, Fault):
pass
@ -231,7 +231,7 @@ class ONVIFDevice:
try:
event_service = self.device.create_events_service()
event_capabilities = await event_service.GetServiceCapabilities()
pullpoint = event_capabilities.WSPullPointSupport
pullpoint = event_capabilities and event_capabilities.WSPullPointSupport
except (ONVIFError, Fault):
pass