Last active
November 24, 2016 04:10
-
-
Save tchellomello/0cc929b9ac425bcfab166323d1db450a to your computer and use it in GitHub Desktop.
V1.0 amcrest camera for Home Assistant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| 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 amcrest import AmcrestCamera | |
| 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 | |
| REQUIREMENTS = ['git+https://github.com/tchellomello/python-amcrest' | |
| '#amcrest==1.0.0'] | |
| _LOGGER = logging.getLogger(__name__) | |
| DEFAULT_PORT = 80 | |
| DEFAULT_NAME = 'Amcrest Camera' | |
| 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.""" | |
| add_devices([AmcrestCam(config)]) | |
| return True | |
| class AmcrestCam(Camera): | |
| """An implementation of an Amcrest IP camera.""" | |
| def __init__(self, device_info): | |
| """Initialize an Amcrest camera.""" | |
| super(AmcrestCam, self).__init__() | |
| self._name = device_info.get(CONF_NAME) | |
| self._data = AmcrestCamera(device_info.get(CONF_HOST), | |
| device_info.get(CONF_PORT), | |
| device_info.get(CONF_USERNAME), | |
| device_info.get(CONF_PASSWORD)) | |
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To install the module:
Configuration: