From d39883211277b09be1f547690ba2d2a178a8e570 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 22 Feb 2016 13:17:53 -0800 Subject: [PATCH] Make UVC cameras honor the local camera password store, if set The NVR tells us the admin username, but not the password for the camera. Right now, we assume the default password, which obviously doesn't work for people that have changed it. The uvcclient library provides a way to set the cached admin password for a camera, which is stored in a client-specific location. We can utilize that to grab the password, falling back to the default if it's unset. With this, people just need to run a command per camera to set the admin password on their systems, if it has changed. --- homeassistant/components/camera/uvc.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/camera/uvc.py b/homeassistant/components/camera/uvc.py index a1ae128f4da..c69f1f18e1f 100644 --- a/homeassistant/components/camera/uvc.py +++ b/homeassistant/components/camera/uvc.py @@ -14,7 +14,7 @@ import requests from homeassistant.components.camera import DOMAIN, Camera from homeassistant.helpers import validate_config -REQUIREMENTS = ['uvcclient==0.6'] +REQUIREMENTS = ['uvcclient==0.8'] _LOGGER = logging.getLogger(__name__) @@ -81,18 +81,27 @@ class UnifiVideoCamera(Camera): def _login(self): from uvcclient import camera as uvc_camera + from uvcclient import store as uvc_store + caminfo = self._nvr.get_camera(self._uuid) if self._connect_addr: addrs = [self._connect_addr] else: addrs = [caminfo['host'], caminfo['internalHost']] + store = uvc_store.get_info_store() + password = store.get_camera_password(self._uuid) + if password is None: + _LOGGER.debug('Logging into camera %(name)s with default password', + dict(name=self._name)) + password = 'ubnt' + camera = None for addr in addrs: try: camera = uvc_camera.UVCCameraClient(addr, caminfo['username'], - 'ubnt') + password) camera.login() _LOGGER.debug('Logged into UVC camera %(name)s via %(addr)s', dict(name=self._name, addr=addr))