Skip to content
Permalink
Browse files

fix mjpeg issue along with some cameras not returning event capabilit…

…ies properly (#35885)
  • Loading branch information
hunterjm authored and pvizeli committed May 21, 2020
1 parent c7008eb commit ae66f4250c9b2e426abfdc8b0dd66a032c1640b6
Showing with 12 additions and 12 deletions.
  1. +10 −10 homeassistant/components/onvif/camera.py
  2. +2 −2 homeassistant/components/onvif/device.py
@@ -106,23 +106,13 @@ def entity_registry_enabled_default(self) -> bool:

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):
"""Return a still image response from the 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 @@ async def handle_async_mjpeg_stream(self, request):
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,
@@ -223,15 +223,15 @@ async def async_get_capabilities(self):
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

pullpoint = False
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

0 comments on commit ae66f42

Please sign in to comment.
You can’t perform that action at this time.