From 29f15393b13cea315a6aa2bb29c371d18ef87c52 Mon Sep 17 00:00:00 2001 From: Carlos Gustavo Sarmiento Date: Sat, 1 Dec 2018 02:58:59 -0800 Subject: [PATCH] Updated UVC camera component to support SSL connections (#18829) --- homeassistant/components/camera/uvc.py | 9 ++++++--- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/camera/test_uvc.py | 21 ++++++++++++++++++--- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/camera/uvc.py b/homeassistant/components/camera/uvc.py index 0e65ac77c1f..50e7c3d8fe2 100644 --- a/homeassistant/components/camera/uvc.py +++ b/homeassistant/components/camera/uvc.py @@ -10,12 +10,12 @@ import socket import requests import voluptuous as vol -from homeassistant.const import CONF_PORT +from homeassistant.const import CONF_PORT, CONF_SSL from homeassistant.components.camera import Camera, PLATFORM_SCHEMA import homeassistant.helpers.config_validation as cv from homeassistant.exceptions import PlatformNotReady -REQUIREMENTS = ['uvcclient==0.10.1'] +REQUIREMENTS = ['uvcclient==0.11.0'] _LOGGER = logging.getLogger(__name__) @@ -25,12 +25,14 @@ CONF_PASSWORD = 'password' DEFAULT_PASSWORD = 'ubnt' DEFAULT_PORT = 7080 +DEFAULT_SSL = False PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_NVR): cv.string, vol.Required(CONF_KEY): cv.string, vol.Optional(CONF_PASSWORD, default=DEFAULT_PASSWORD): cv.string, vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, + vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean, }) @@ -40,11 +42,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None): key = config[CONF_KEY] password = config[CONF_PASSWORD] port = config[CONF_PORT] + ssl = config[CONF_SSL] from uvcclient import nvr try: # Exceptions may be raised in all method calls to the nvr library. - nvrconn = nvr.UVCRemote(addr, port, key) + nvrconn = nvr.UVCRemote(addr, port, key, ssl=ssl) cameras = nvrconn.index() identifier = 'id' if nvrconn.server_version >= (3, 2, 0) else 'uuid' diff --git a/requirements_all.txt b/requirements_all.txt index 249f4f30a65..40cc0d39c43 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1575,7 +1575,7 @@ upsmychoice==1.0.6 uscisstatus==0.1.1 # homeassistant.components.camera.uvc -uvcclient==0.10.1 +uvcclient==0.11.0 # homeassistant.components.climate.venstar venstarcolortouch==0.6 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index e7fed2cb686..935757b37d7 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -255,7 +255,7 @@ srpenergy==1.0.5 statsd==3.2.1 # homeassistant.components.camera.uvc -uvcclient==0.10.1 +uvcclient==0.11.0 # homeassistant.components.vultr vultr==0.1.2 diff --git a/tests/components/camera/test_uvc.py b/tests/components/camera/test_uvc.py index b41cb9f865b..476e612eb06 100644 --- a/tests/components/camera/test_uvc.py +++ b/tests/components/camera/test_uvc.py @@ -55,7 +55,12 @@ class TestUVCSetup(unittest.TestCase): assert setup_component(self.hass, 'camera', {'camera': config}) assert mock_remote.call_count == 1 - assert mock_remote.call_args == mock.call('foo', 123, 'secret') + assert mock_remote.call_args == mock.call( + 'foo', + 123, + 'secret', + ssl=False + ) mock_uvc.assert_has_calls([ mock.call(mock_remote.return_value, 'id1', 'Front', 'bar'), mock.call(mock_remote.return_value, 'id2', 'Back', 'bar'), @@ -81,7 +86,12 @@ class TestUVCSetup(unittest.TestCase): assert setup_component(self.hass, 'camera', {'camera': config}) assert mock_remote.call_count == 1 - assert mock_remote.call_args == mock.call('foo', 7080, 'secret') + assert mock_remote.call_args == mock.call( + 'foo', + 7080, + 'secret', + ssl=False + ) mock_uvc.assert_has_calls([ mock.call(mock_remote.return_value, 'id1', 'Front', 'ubnt'), mock.call(mock_remote.return_value, 'id2', 'Back', 'ubnt'), @@ -107,7 +117,12 @@ class TestUVCSetup(unittest.TestCase): assert setup_component(self.hass, 'camera', {'camera': config}) assert mock_remote.call_count == 1 - assert mock_remote.call_args == mock.call('foo', 7080, 'secret') + assert mock_remote.call_args == mock.call( + 'foo', + 7080, + 'secret', + ssl=False + ) mock_uvc.assert_has_calls([ mock.call(mock_remote.return_value, 'one', 'Front', 'ubnt'), mock.call(mock_remote.return_value, 'two', 'Back', 'ubnt'),