Added support to Amcrest camera (#4573)
* Introduced support to Amcrest IP Cameras * Fixed lint issues * Fixed requirements test * * Implemented test to verify crendentials during camera setup * Added persistent_notification in case of error when during Amcrest setuppull/4419/merge
parent
e5504b39ec
commit
9c6609cb79
|
@ -124,6 +124,7 @@ omit =
|
||||||
homeassistant/components/binary_sensor/concord232.py
|
homeassistant/components/binary_sensor/concord232.py
|
||||||
homeassistant/components/binary_sensor/rest.py
|
homeassistant/components/binary_sensor/rest.py
|
||||||
homeassistant/components/browser.py
|
homeassistant/components/browser.py
|
||||||
|
homeassistant/components/camera/amcrest.py
|
||||||
homeassistant/components/camera/bloomsky.py
|
homeassistant/components/camera/bloomsky.py
|
||||||
homeassistant/components/camera/foscam.py
|
homeassistant/components/camera/foscam.py
|
||||||
homeassistant/components/camera/mjpeg.py
|
homeassistant/components/camera/mjpeg.py
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
"""
|
||||||
|
This component provides basic support for Amcrest IP cameras.
|
||||||
|
|
||||||
|
For more details about this platform, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/camera.amcrest/
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.components.camera import (Camera, PLATFORM_SCHEMA)
|
||||||
|
from homeassistant.const import (
|
||||||
|
CONF_HOST, CONF_NAME, CONF_USERNAME, CONF_PASSWORD, CONF_PORT)
|
||||||
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
import homeassistant.loader as loader
|
||||||
|
|
||||||
|
REQUIREMENTS = ['amcrest==1.0.0']
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DEFAULT_PORT = 80
|
||||||
|
DEFAULT_NAME = 'Amcrest Camera'
|
||||||
|
|
||||||
|
NOTIFICATION_ID = 'amcrest_notification'
|
||||||
|
NOTIFICATION_TITLE = 'Amcrest Camera Setup'
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_HOST): cv.string,
|
||||||
|
vol.Required(CONF_USERNAME): cv.string,
|
||||||
|
vol.Required(CONF_PASSWORD): cv.string,
|
||||||
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
|
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
"""Setup an Amcrest IP Camera."""
|
||||||
|
from amcrest import AmcrestCamera
|
||||||
|
data = AmcrestCamera(config.get(CONF_HOST),
|
||||||
|
config.get(CONF_PORT),
|
||||||
|
config.get(CONF_USERNAME),
|
||||||
|
config.get(CONF_PASSWORD))
|
||||||
|
|
||||||
|
persistent_notification = loader.get_component('persistent_notification')
|
||||||
|
try:
|
||||||
|
data.camera.current_time
|
||||||
|
# pylint: disable=broad-except
|
||||||
|
except Exception as ex:
|
||||||
|
_LOGGER.error('Unable to connect to Amcrest camera: %s', str(ex))
|
||||||
|
persistent_notification.create(
|
||||||
|
hass, 'Error: {}<br />'
|
||||||
|
'You will need to restart hass after fixing.'
|
||||||
|
''.format(ex),
|
||||||
|
title=NOTIFICATION_TITLE,
|
||||||
|
notification_id=NOTIFICATION_ID)
|
||||||
|
return False
|
||||||
|
|
||||||
|
add_devices([AmcrestCam(config, data)])
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class AmcrestCam(Camera):
|
||||||
|
"""An implementation of an Amcrest IP camera."""
|
||||||
|
|
||||||
|
def __init__(self, device_info, data):
|
||||||
|
"""Initialize an Amcrest camera."""
|
||||||
|
super(AmcrestCam, self).__init__()
|
||||||
|
self._name = device_info.get(CONF_NAME)
|
||||||
|
self._data = data
|
||||||
|
|
||||||
|
def camera_image(self):
|
||||||
|
"""Return a still image reponse from the camera."""
|
||||||
|
# Send the request to snap a picture and return raw jpg data
|
||||||
|
response = self._data.camera.snapshot()
|
||||||
|
return response.data
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""Return the name of this camera."""
|
||||||
|
return self._name
|
|
@ -33,6 +33,9 @@ TwitterAPI==2.4.2
|
||||||
# homeassistant.components.http
|
# homeassistant.components.http
|
||||||
aiohttp_cors==0.5.0
|
aiohttp_cors==0.5.0
|
||||||
|
|
||||||
|
# homeassistant.components.camera.amcrest
|
||||||
|
amcrest==1.0.0
|
||||||
|
|
||||||
# homeassistant.components.apcupsd
|
# homeassistant.components.apcupsd
|
||||||
apcaccess==0.0.4
|
apcaccess==0.0.4
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue