Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ONVIF component to SUPPORT_STREAM #22569

Merged
merged 5 commits into from Mar 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions homeassistant/components/onvif/camera.py
Expand Up @@ -13,7 +13,8 @@
from homeassistant.const import (
CONF_NAME, CONF_HOST, CONF_USERNAME, CONF_PASSWORD, CONF_PORT,
ATTR_ENTITY_ID)
from homeassistant.components.camera import Camera, PLATFORM_SCHEMA
from homeassistant.components.camera import (
Camera, PLATFORM_SCHEMA, SUPPORT_STREAM)
from homeassistant.components.camera.const import DOMAIN
from homeassistant.components.ffmpeg import (
DATA_FFMPEG, CONF_EXTRA_ARGUMENTS)
Expand Down Expand Up @@ -187,13 +188,14 @@ async def async_added_to_hass(self):
self.hass.data[ONVIF_DATA] = {}
self.hass.data[ONVIF_DATA][ENTITIES] = []
self.hass.data[ONVIF_DATA][ENTITIES].append(self)
await self.hass.async_add_executor_job(self.obtain_input_uri)

async def async_camera_image(self):
"""Return a still image response from the camera."""
from haffmpeg.tools import ImageFrame, IMAGE_JPEG

if not self._input:
await self.hass.async_add_job(self.obtain_input_uri)
await self.hass.async_add_executor_job(self.obtain_input_uri)
if not self._input:
return None

Expand All @@ -210,7 +212,7 @@ async def handle_async_mjpeg_stream(self, request):
from haffmpeg.camera import CameraMjpeg

if not self._input:
await self.hass.async_add_job(self.obtain_input_uri)
await self.hass.async_add_executor_job(self.obtain_input_uri)
if not self._input:
return None

Expand All @@ -228,6 +230,18 @@ async def handle_async_mjpeg_stream(self, request):
finally:
await stream.close()

@property
def supported_features(self):
"""Return supported features."""
if self._input:
return SUPPORT_STREAM
return 0

@property
def stream_source(self):
"""Return the stream source."""
return self._input

@property
def name(self):
"""Return the name of this camera."""
Expand Down