diff --git a/homeassistant/components/uvc/camera.py b/homeassistant/components/uvc/camera.py index b9a6262cd4f..cd6875cdcdc 100644 --- a/homeassistant/components/uvc/camera.py +++ b/homeassistant/components/uvc/camera.py @@ -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 diff --git a/tests/components/uvc/test_camera.py b/tests/components/uvc/test_camera.py index c77b5d83749..b95d940bda4 100644 --- a/tests/components/uvc/test_camera.py +++ b/tests/components/uvc/test_camera.py @@ -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")