mirror of
https://github.com/home-assistant/core.git
synced 2025-08-02 04:05:06 +02:00
Fix Xeoma camera platform to allow different admin/viewer credentials (#12161)
This commit is contained in:
committed by
Paulus Schoutsen
parent
49c7b422f2
commit
a2916a9c47
2
.gitignore
vendored
2
.gitignore
vendored
@@ -16,7 +16,9 @@ Icon
|
|||||||
# Thumbnails
|
# Thumbnails
|
||||||
._*
|
._*
|
||||||
|
|
||||||
|
# IntelliJ IDEA
|
||||||
.idea
|
.idea
|
||||||
|
*.iml
|
||||||
|
|
||||||
# pytest
|
# pytest
|
||||||
.cache
|
.cache
|
||||||
|
@@ -14,7 +14,7 @@ from homeassistant.const import (
|
|||||||
CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME)
|
CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME)
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['pyxeoma==1.2']
|
REQUIREMENTS = ['pyxeoma==1.3']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -22,6 +22,8 @@ CONF_CAMERAS = 'cameras'
|
|||||||
CONF_HIDE = 'hide'
|
CONF_HIDE = 'hide'
|
||||||
CONF_IMAGE_NAME = 'image_name'
|
CONF_IMAGE_NAME = 'image_name'
|
||||||
CONF_NEW_VERSION = 'new_version'
|
CONF_NEW_VERSION = 'new_version'
|
||||||
|
CONF_VIEWER_PASSWORD = 'viewer_password'
|
||||||
|
CONF_VIEWER_USERNAME = 'viewer_username'
|
||||||
|
|
||||||
CAMERAS_SCHEMA = vol.Schema({
|
CAMERAS_SCHEMA = vol.Schema({
|
||||||
vol.Required(CONF_IMAGE_NAME): cv.string,
|
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]
|
host = config[CONF_HOST]
|
||||||
login = config.get(CONF_USERNAME)
|
login = config.get(CONF_USERNAME)
|
||||||
password = config.get(CONF_PASSWORD)
|
password = config.get(CONF_PASSWORD)
|
||||||
new_version = config[CONF_NEW_VERSION]
|
|
||||||
|
|
||||||
xeoma = Xeoma(host, new_version, login, password)
|
xeoma = Xeoma(host, login, password)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield from xeoma.async_test_connection()
|
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_IMAGE_NAME: image_name,
|
||||||
CONF_HIDE: False,
|
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]:
|
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))
|
cameras = list(filter(lambda c: not c[CONF_HIDE], discovered_cameras))
|
||||||
async_add_devices(
|
async_add_devices(
|
||||||
[XeomaCamera(xeoma, camera[CONF_IMAGE_NAME], camera[CONF_NAME])
|
[XeomaCamera(xeoma, camera[CONF_IMAGE_NAME], camera[CONF_NAME],
|
||||||
for camera in cameras])
|
camera[CONF_VIEWER_USERNAME],
|
||||||
|
camera[CONF_VIEWER_PASSWORD]) for camera in cameras])
|
||||||
except XeomaError as err:
|
except XeomaError as err:
|
||||||
_LOGGER.error("Error: %s", err.message)
|
_LOGGER.error("Error: %s", err.message)
|
||||||
return
|
return
|
||||||
@@ -87,12 +92,14 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||||||
class XeomaCamera(Camera):
|
class XeomaCamera(Camera):
|
||||||
"""Implementation of a Xeoma camera."""
|
"""Implementation of a Xeoma camera."""
|
||||||
|
|
||||||
def __init__(self, xeoma, image, name):
|
def __init__(self, xeoma, image, name, username, password):
|
||||||
"""Initialize a Xeoma camera."""
|
"""Initialize a Xeoma camera."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._xeoma = xeoma
|
self._xeoma = xeoma
|
||||||
self._name = name
|
self._name = name
|
||||||
self._image = image
|
self._image = image
|
||||||
|
self._username = username
|
||||||
|
self._password = password
|
||||||
self._last_image = None
|
self._last_image = None
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@@ -100,7 +107,8 @@ class XeomaCamera(Camera):
|
|||||||
"""Return a still image response from the camera."""
|
"""Return a still image response from the camera."""
|
||||||
from pyxeoma.xeoma import XeomaError
|
from pyxeoma.xeoma import XeomaError
|
||||||
try:
|
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
|
self._last_image = image
|
||||||
except XeomaError as err:
|
except XeomaError as err:
|
||||||
_LOGGER.error("Error fetching image: %s", err.message)
|
_LOGGER.error("Error fetching image: %s", err.message)
|
||||||
|
@@ -1015,7 +1015,7 @@ pywebpush==1.5.0
|
|||||||
pywemo==0.4.25
|
pywemo==0.4.25
|
||||||
|
|
||||||
# homeassistant.components.camera.xeoma
|
# homeassistant.components.camera.xeoma
|
||||||
pyxeoma==1.2
|
pyxeoma==1.3
|
||||||
|
|
||||||
# homeassistant.components.zabbix
|
# homeassistant.components.zabbix
|
||||||
pyzabbix==0.7.4
|
pyzabbix==0.7.4
|
||||||
|
Reference in New Issue
Block a user