Add RTSP stream support for UVC (Unifi Video Client) integration (#30297)

* Add SUPPORT_STREAM to supported_features.

* Implement stream_source with channel RTSP URIs.

* Add Tests for Stream Support.

* Make stream_source async.

* Removed unused import.

* Re-wrote test to remove warning, and lint error.
pull/29828/head
ochlocracy 2020-01-03 05:30:26 -05:00 committed by Paulus Schoutsen
parent b097a64010
commit 3a18ef219b
2 changed files with 49 additions and 1 deletions

View File

@ -6,7 +6,7 @@ import requests
from uvcclient import camera as uvc_camera, nvr
import voluptuous as vol
from homeassistant.components.camera import PLATFORM_SCHEMA, Camera
from homeassistant.components.camera import PLATFORM_SCHEMA, SUPPORT_STREAM, Camera
from homeassistant.const import CONF_PORT, CONF_SSL
from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv
@ -92,6 +92,17 @@ class UnifiVideoCamera(Camera):
"""Return the name of this camera."""
return self._name
@property
def supported_features(self):
"""Return supported features."""
caminfo = self._nvr.get_camera(self._uuid)
channels = caminfo["channels"]
for channel in channels:
if channel["isRtspEnabled"]:
return SUPPORT_STREAM
return 0
@property
def is_recording(self):
"""Return true if the camera is recording."""
@ -199,3 +210,13 @@ class UnifiVideoCamera(Camera):
def disable_motion_detection(self):
"""Disable motion detection in camera."""
self.set_motion_detection(False)
async def stream_source(self):
"""Return the source of the stream."""
caminfo = self._nvr.get_camera(self._uuid)
channels = caminfo["channels"]
for channel in channels:
if channel["isRtspEnabled"]:
return channel["rtspUris"][0]
return None

View File

@ -7,6 +7,7 @@ import pytest
import requests
from uvcclient import camera, nvr
from homeassistant.components.camera import SUPPORT_STREAM
from homeassistant.components.uvc import camera as uvc
from homeassistant.exceptions import PlatformNotReady
from homeassistant.setup import setup_component
@ -190,6 +191,26 @@ class TestUVC(unittest.TestCase):
"host": "host-a",
"internalHost": "host-b",
"username": "admin",
"channels": [
{
"id": "0",
"width": 1920,
"height": 1080,
"fps": 25,
"bitrate": 6000000,
"isRtspEnabled": True,
"rtspUris": ["rtsp://host-a:7447/uuid_rtspchannel_0"],
},
{
"id": "1",
"width": 1024,
"height": 576,
"fps": 15,
"bitrate": 1200000,
"isRtspEnabled": False,
"rtspUris": ["rtsp://host-a:7447/uuid_rtspchannel_1"],
},
],
}
self.nvr.server_version = (3, 2, 0)
@ -199,6 +220,12 @@ class TestUVC(unittest.TestCase):
assert self.uvc.is_recording
assert "Ubiquiti" == self.uvc.brand
assert "UVC Fake" == self.uvc.model
assert SUPPORT_STREAM == self.uvc.supported_features
def test_stream(self):
"""Test the RTSP stream URI."""
stream_source = yield from self.uvc.stream_source()
assert stream_source == "rtsp://host-a:7447/uuid_rtspchannel_0"
@mock.patch("uvcclient.store.get_info_store")
@mock.patch("uvcclient.camera.UVCCameraClientV320")