2019-02-13 21:21:14 +01:00
|
|
|
|
"""Support for Axis camera streaming."""
|
2017-05-12 17:51:54 +02:00
|
|
|
|
|
2019-04-05 19:14:54 +02:00
|
|
|
|
from homeassistant.components.camera import SUPPORT_STREAM
|
2019-03-16 20:44:05 -07:00
|
|
|
|
from homeassistant.components.mjpeg.camera import (
|
2019-07-31 12:25:30 -07:00
|
|
|
|
CONF_MJPEG_URL,
|
|
|
|
|
CONF_STILL_IMAGE_URL,
|
|
|
|
|
MjpegCamera,
|
|
|
|
|
filter_urllib3_logging,
|
|
|
|
|
)
|
2018-01-21 07:35:38 +01:00
|
|
|
|
from homeassistant.const import (
|
2019-07-31 12:25:30 -07:00
|
|
|
|
CONF_AUTHENTICATION,
|
|
|
|
|
CONF_HOST,
|
|
|
|
|
CONF_NAME,
|
|
|
|
|
CONF_PASSWORD,
|
|
|
|
|
CONF_PORT,
|
|
|
|
|
CONF_USERNAME,
|
|
|
|
|
HTTP_DIGEST_AUTHENTICATION,
|
|
|
|
|
)
|
2019-03-24 16:16:50 +01:00
|
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2017-05-12 17:51:54 +02:00
|
|
|
|
|
2019-05-20 07:45:31 +02:00
|
|
|
|
from .axis_base import AxisEntityBase
|
2019-03-24 16:16:50 +01:00
|
|
|
|
from .const import DOMAIN as AXIS_DOMAIN
|
2017-05-12 17:51:54 +02:00
|
|
|
|
|
|
|
|
|
|
2019-03-24 16:16:50 +01:00
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
|
"""Set up the Axis camera video stream."""
|
2019-01-03 13:56:36 -05:00
|
|
|
|
filter_urllib3_logging()
|
|
|
|
|
|
2020-01-04 08:58:18 +01:00
|
|
|
|
device = hass.data[AXIS_DOMAIN][config_entry.unique_id]
|
2019-03-24 16:16:50 +01:00
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
CONF_NAME: config_entry.data[CONF_NAME],
|
2020-01-30 22:20:30 +01:00
|
|
|
|
CONF_USERNAME: config_entry.data[CONF_USERNAME],
|
|
|
|
|
CONF_PASSWORD: config_entry.data[CONF_PASSWORD],
|
2020-02-23 22:38:05 +01:00
|
|
|
|
CONF_MJPEG_URL: (
|
|
|
|
|
f"http://{config_entry.data[CONF_HOST]}"
|
|
|
|
|
f":{config_entry.data[CONF_PORT]}/axis-cgi/mjpg/video.cgi"
|
2019-07-31 12:25:30 -07:00
|
|
|
|
),
|
2020-02-23 22:38:05 +01:00
|
|
|
|
CONF_STILL_IMAGE_URL: (
|
|
|
|
|
f"http://{config_entry.data[CONF_HOST]}"
|
|
|
|
|
f":{config_entry.data[CONF_PORT]}/axis-cgi/jpg/image.cgi"
|
2019-07-31 12:25:30 -07:00
|
|
|
|
),
|
2017-05-12 17:51:54 +02:00
|
|
|
|
CONF_AUTHENTICATION: HTTP_DIGEST_AUTHENTICATION,
|
|
|
|
|
}
|
2019-03-24 16:16:50 +01:00
|
|
|
|
async_add_entities([AxisCamera(config, device)])
|
2017-06-24 09:14:57 +02:00
|
|
|
|
|
|
|
|
|
|
2019-05-20 07:45:31 +02:00
|
|
|
|
class AxisCamera(AxisEntityBase, MjpegCamera):
|
2018-01-21 07:35:38 +01:00
|
|
|
|
"""Representation of a Axis camera."""
|
2017-06-24 09:14:57 +02:00
|
|
|
|
|
2019-03-24 16:16:50 +01:00
|
|
|
|
def __init__(self, config, device):
|
2017-06-24 09:14:57 +02:00
|
|
|
|
"""Initialize Axis Communications camera component."""
|
2019-05-20 07:45:31 +02:00
|
|
|
|
AxisEntityBase.__init__(self, device)
|
|
|
|
|
MjpegCamera.__init__(self, config)
|
2019-03-24 16:16:50 +01:00
|
|
|
|
|
|
|
|
|
async def async_added_to_hass(self):
|
|
|
|
|
"""Subscribe camera events."""
|
2019-07-31 12:25:30 -07:00
|
|
|
|
self.unsub_dispatcher.append(
|
|
|
|
|
async_dispatcher_connect(
|
|
|
|
|
self.hass, self.device.event_new_address, self._new_address
|
|
|
|
|
)
|
|
|
|
|
)
|
2019-03-29 15:20:12 +01:00
|
|
|
|
|
2019-05-20 07:45:31 +02:00
|
|
|
|
await super().async_added_to_hass()
|
2019-04-16 00:06:45 +02:00
|
|
|
|
|
2019-04-05 19:14:54 +02:00
|
|
|
|
@property
|
|
|
|
|
def supported_features(self):
|
|
|
|
|
"""Return supported features."""
|
|
|
|
|
return SUPPORT_STREAM
|
|
|
|
|
|
2019-05-23 09:45:30 -07:00
|
|
|
|
async def stream_source(self):
|
2019-04-05 19:14:54 +02:00
|
|
|
|
"""Return the stream source."""
|
2020-02-23 22:38:05 +01:00
|
|
|
|
return (
|
|
|
|
|
f"rtsp://{self.device.config_entry.data[CONF_USERNAME]}´"
|
|
|
|
|
f":{self.device.config_entry.data[CONF_PASSWORD]}"
|
|
|
|
|
f"@{self.device.host}/axis-media/media.amp?videocodec=h264"
|
2019-07-31 12:25:30 -07:00
|
|
|
|
)
|
2019-04-05 19:14:54 +02:00
|
|
|
|
|
2019-04-02 20:13:11 +02:00
|
|
|
|
def _new_address(self):
|
|
|
|
|
"""Set new device address for video stream."""
|
2020-01-30 22:20:30 +01:00
|
|
|
|
port = self.device.config_entry.data[CONF_PORT]
|
2020-02-23 22:38:05 +01:00
|
|
|
|
self._mjpeg_url = (f"http://{self.device.host}:{port}/axis-cgi/mjpg/video.cgi",)
|
|
|
|
|
self._still_image_url = (
|
|
|
|
|
f"http://{self.device.host}:{port}/axis-cgi/jpg/image.cgi"
|
|
|
|
|
)
|
2019-03-27 18:25:01 +01:00
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def unique_id(self):
|
|
|
|
|
"""Return a unique identifier for this device."""
|
2019-09-03 16:11:36 +02:00
|
|
|
|
return f"{self.device.serial}-camera"
|