2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Axis camera streaming."""
|
2017-05-12 15:51:54 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.camera.mjpeg import (
|
2019-01-03 18:56:36 +00:00
|
|
|
CONF_MJPEG_URL, CONF_STILL_IMAGE_URL, MjpegCamera, filter_urllib3_logging)
|
2018-01-21 06:35:38 +00:00
|
|
|
from homeassistant.const import (
|
|
|
|
CONF_AUTHENTICATION, CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_PORT,
|
|
|
|
CONF_USERNAME, HTTP_DIGEST_AUTHENTICATION)
|
2017-10-25 07:04:30 +00:00
|
|
|
from homeassistant.helpers.dispatcher import dispatcher_connect
|
2017-05-12 15:51:54 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
DOMAIN = 'axis'
|
2017-06-24 07:14:57 +00:00
|
|
|
DEPENDENCIES = [DOMAIN]
|
2017-05-12 15:51:54 +00:00
|
|
|
|
|
|
|
|
2017-09-19 08:09:47 +00:00
|
|
|
def _get_image_url(host, port, mode):
|
2018-01-21 06:35:38 +00:00
|
|
|
"""Set the URL to get the image."""
|
2017-05-12 15:51:54 +00:00
|
|
|
if mode == 'mjpeg':
|
2017-09-19 08:09:47 +00:00
|
|
|
return 'http://{}:{}/axis-cgi/mjpg/video.cgi'.format(host, port)
|
2018-07-23 08:16:05 +00:00
|
|
|
if mode == 'single':
|
2017-09-19 08:09:47 +00:00
|
|
|
return 'http://{}:{}/axis-cgi/jpg/image.cgi'.format(host, port)
|
2017-05-12 15:51:54 +00:00
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2018-01-21 06:35:38 +00:00
|
|
|
"""Set up the Axis camera."""
|
2019-01-03 18:56:36 +00:00
|
|
|
filter_urllib3_logging()
|
|
|
|
|
2017-09-19 08:09:47 +00:00
|
|
|
camera_config = {
|
2017-06-24 07:14:57 +00:00
|
|
|
CONF_NAME: discovery_info[CONF_NAME],
|
|
|
|
CONF_USERNAME: discovery_info[CONF_USERNAME],
|
|
|
|
CONF_PASSWORD: discovery_info[CONF_PASSWORD],
|
2018-01-21 06:35:38 +00:00
|
|
|
CONF_MJPEG_URL: _get_image_url(
|
|
|
|
discovery_info[CONF_HOST], str(discovery_info[CONF_PORT]),
|
|
|
|
'mjpeg'),
|
|
|
|
CONF_STILL_IMAGE_URL: _get_image_url(
|
|
|
|
discovery_info[CONF_HOST], str(discovery_info[CONF_PORT]),
|
|
|
|
'single'),
|
2017-05-12 15:51:54 +00:00
|
|
|
CONF_AUTHENTICATION: HTTP_DIGEST_AUTHENTICATION,
|
|
|
|
}
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities([AxisCamera(
|
2018-01-21 06:35:38 +00:00
|
|
|
hass, camera_config, str(discovery_info[CONF_PORT]))])
|
2017-06-24 07:14:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AxisCamera(MjpegCamera):
|
2018-01-21 06:35:38 +00:00
|
|
|
"""Representation of a Axis camera."""
|
2017-06-24 07:14:57 +00:00
|
|
|
|
2017-09-19 08:09:47 +00:00
|
|
|
def __init__(self, hass, config, port):
|
2017-06-24 07:14:57 +00:00
|
|
|
"""Initialize Axis Communications camera component."""
|
2018-09-15 09:26:29 +00:00
|
|
|
super().__init__(config)
|
2017-09-19 08:09:47 +00:00
|
|
|
self.port = port
|
2018-01-21 06:35:38 +00:00
|
|
|
dispatcher_connect(
|
|
|
|
hass, DOMAIN + '_' + config[CONF_NAME] + '_new_ip', self._new_ip)
|
2017-06-24 07:14:57 +00:00
|
|
|
|
|
|
|
def _new_ip(self, host):
|
|
|
|
"""Set new IP for video stream."""
|
2017-09-19 08:09:47 +00:00
|
|
|
self._mjpeg_url = _get_image_url(host, self.port, 'mjpeg')
|
|
|
|
self._still_image_url = _get_image_url(host, self.port, 'single')
|