Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Xeoma camera platform to allow different admin/viewer credentials #12161

Merged
merged 1 commit into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Icon
# Thumbnails
._*

# IntelliJ IDEA
.idea
*.iml

# pytest
.cache
Expand Down
26 changes: 17 additions & 9 deletions homeassistant/components/camera/xeoma.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
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__)

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,
Expand All @@ -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()
Expand All @@ -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]:
Expand All @@ -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
Expand All @@ -87,20 +92,23 @@ 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
def async_camera_image(self):
"""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)
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,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
Expand Down