diff --git a/homeassistant/components/uvc/camera.py b/homeassistant/components/uvc/camera.py index 5878023bf2e..3e0363f4f35 100644 --- a/homeassistant/components/uvc/camera.py +++ b/homeassistant/components/uvc/camera.py @@ -1,5 +1,6 @@ """Support for Ubiquiti's UVC cameras.""" import logging +import re import requests from uvcclient import camera as uvc_camera, nvr @@ -213,7 +214,16 @@ class UnifiVideoCamera(Camera): """Return the source of the stream.""" for channel in self._caminfo["channels"]: if channel["isRtspEnabled"]: - return channel["rtspUris"][0] + uri = next( + ( + uri + for i, uri in enumerate(channel["rtspUris"]) + # pylint: disable=protected-access + if re.search(self._nvr._host, uri) + # pylint: enable=protected-access + ) + ) + return uri return None diff --git a/tests/components/uvc/test_camera.py b/tests/components/uvc/test_camera.py index 2b1e9c7782e..1556a165447 100644 --- a/tests/components/uvc/test_camera.py +++ b/tests/components/uvc/test_camera.py @@ -199,7 +199,10 @@ class TestUVC(unittest.TestCase): "fps": 25, "bitrate": 6000000, "isRtspEnabled": True, - "rtspUris": ["rtsp://host-a:7447/uuid_rtspchannel_0"], + "rtspUris": [ + "rtsp://host-a:7447/uuid_rtspchannel_0", + "rtsp://foo:7447/uuid_rtspchannel_0", + ], }, { "id": "1", @@ -208,7 +211,10 @@ class TestUVC(unittest.TestCase): "fps": 15, "bitrate": 1200000, "isRtspEnabled": False, - "rtspUris": ["rtsp://host-a:7447/uuid_rtspchannel_1"], + "rtspUris": [ + "rtsp://host-a:7447/uuid_rtspchannel_1", + "rtsp://foo:7447/uuid_rtspchannel_1", + ], }, ], } @@ -226,7 +232,7 @@ class TestUVC(unittest.TestCase): 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" + assert stream_source == "rtsp://foo:7447/uuid_rtspchannel_0" @mock.patch("uvcclient.store.get_info_store") @mock.patch("uvcclient.camera.UVCCameraClientV320")