From a2916a9c477294a83a9dc634f2f391185edb7ca1 Mon Sep 17 00:00:00 2001
From: Jerad Meisner <jerad.meisner@gmail.com>
Date: Tue, 6 Feb 2018 10:47:38 -0800
Subject: [PATCH] Fix Xeoma camera platform to allow different admin/viewer
 credentials (#12161)

---
 .gitignore                               |  2 ++
 homeassistant/components/camera/xeoma.py | 26 ++++++++++++++++--------
 requirements_all.txt                     |  2 +-
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/.gitignore b/.gitignore
index fe26f43e8bc..0d55cae3c9d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,7 +16,9 @@ Icon
 # Thumbnails
 ._*
 
+# IntelliJ IDEA
 .idea
+*.iml
 
 # pytest
 .cache
diff --git a/homeassistant/components/camera/xeoma.py b/homeassistant/components/camera/xeoma.py
index 72f40cb83a4..b4bcad0064d 100755
--- a/homeassistant/components/camera/xeoma.py
+++ b/homeassistant/components/camera/xeoma.py
@@ -14,7 +14,7 @@ from homeassistant.const import (
     CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME)
 from homeassistant.helpers import config_validation as cv
 
-REQUIREMENTS = ['pyxeoma==1.2']
+REQUIREMENTS = ['pyxeoma==1.3']
 
 _LOGGER = logging.getLogger(__name__)
 
@@ -22,6 +22,8 @@ CONF_CAMERAS = 'cameras'
 CONF_HIDE = 'hide'
 CONF_IMAGE_NAME = 'image_name'
 CONF_NEW_VERSION = 'new_version'
+CONF_VIEWER_PASSWORD = 'viewer_password'
+CONF_VIEWER_USERNAME = 'viewer_username'
 
 CAMERAS_SCHEMA = vol.Schema({
     vol.Required(CONF_IMAGE_NAME): cv.string,
@@ -48,9 +50,8 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
     host = config[CONF_HOST]
     login = config.get(CONF_USERNAME)
     password = config.get(CONF_PASSWORD)
-    new_version = config[CONF_NEW_VERSION]
 
-    xeoma = Xeoma(host, new_version, login, password)
+    xeoma = Xeoma(host, login, password)
 
     try:
         yield from xeoma.async_test_connection()
@@ -59,9 +60,12 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
             {
                 CONF_IMAGE_NAME: image_name,
                 CONF_HIDE: False,
-                CONF_NAME: image_name
+                CONF_NAME: image_name,
+                CONF_VIEWER_USERNAME: username,
+                CONF_VIEWER_PASSWORD: pw
+
             }
-            for image_name in discovered_image_names
+            for image_name, username, pw in discovered_image_names
         ]
 
         for cam in config[CONF_CAMERAS]:
@@ -77,8 +81,9 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
 
         cameras = list(filter(lambda c: not c[CONF_HIDE], discovered_cameras))
         async_add_devices(
-            [XeomaCamera(xeoma, camera[CONF_IMAGE_NAME], camera[CONF_NAME])
-             for camera in cameras])
+            [XeomaCamera(xeoma, camera[CONF_IMAGE_NAME], camera[CONF_NAME],
+                         camera[CONF_VIEWER_USERNAME],
+                         camera[CONF_VIEWER_PASSWORD]) for camera in cameras])
     except XeomaError as err:
         _LOGGER.error("Error: %s", err.message)
         return
@@ -87,12 +92,14 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
 class XeomaCamera(Camera):
     """Implementation of a Xeoma camera."""
 
-    def __init__(self, xeoma, image, name):
+    def __init__(self, xeoma, image, name, username, password):
         """Initialize a Xeoma camera."""
         super().__init__()
         self._xeoma = xeoma
         self._name = name
         self._image = image
+        self._username = username
+        self._password = password
         self._last_image = None
 
     @asyncio.coroutine
@@ -100,7 +107,8 @@ class XeomaCamera(Camera):
         """Return a still image response from the camera."""
         from pyxeoma.xeoma import XeomaError
         try:
-            image = yield from self._xeoma.async_get_camera_image(self._image)
+            image = yield from self._xeoma.async_get_camera_image(
+                self._image, self._username, self._password)
             self._last_image = image
         except XeomaError as err:
             _LOGGER.error("Error fetching image: %s", err.message)
diff --git a/requirements_all.txt b/requirements_all.txt
index 804409c946f..6a1d1eeb59f 100644
--- a/requirements_all.txt
+++ b/requirements_all.txt
@@ -1015,7 +1015,7 @@ pywebpush==1.5.0
 pywemo==0.4.25
 
 # homeassistant.components.camera.xeoma
-pyxeoma==1.2
+pyxeoma==1.3
 
 # homeassistant.components.zabbix
 pyzabbix==0.7.4
-- 
GitLab