Add control of Amcrest indicator light (#23986)

Enable feature by default but allow it to be disabled by "control_light: false" in config.

Get brand from camera instead of assuming Amcrest (since this works with other cameras, too.)

Retrieve RTSP URL in update method instead of in stream_source property and in handle_async_mjpeg_stream method.

Move amcrest imports from methods to global.
This commit is contained in:
Phil Bruckner authored and Paulus Schoutsen committed 2019-05-31 13:41:48 -07:00
1 parent 3c1cdecb88
commit d966e0cfce
3 files changed
+45 -30

No files matched your search

+7 -4
View File
@@ -3,6 +3,7 @@ import logging
from datetime import timedelta
import aiohttp
from amcrest import AmcrestCamera, AmcrestError
import voluptuous as vol
from homeassistant.auth.permissions.const import POLICY_CONTROL
@@ -32,6 +33,7 @@ _LOGGER = logging.getLogger(__name__)
CONF_RESOLUTION = 'resolution'
CONF_STREAM_SOURCE = 'stream_source'
CONF_FFMPEG_ARGUMENTS = 'ffmpeg_arguments'
CONF_CONTROL_LIGHT = 'control_light'
DEFAULT_NAME = 'Amcrest Camera'
DEFAULT_PORT = 80
@@ -103,6 +105,7 @@ AMCREST_SCHEMA = vol.All(
_deprecated_sensor_values),
vol.Optional(CONF_SWITCHES):
vol.All(cv.ensure_list, [vol.In(SWITCHES)]),
vol.Optional(CONF_CONTROL_LIGHT, default=True): cv.boolean,
}),
_deprecated_switches
)
@@ -114,8 +117,6 @@ CONFIG_SCHEMA = vol.Schema({
def setup(hass, config):
"""Set up the Amcrest IP Camera component."""
from amcrest import AmcrestCamera, AmcrestError
hass.data.setdefault(DATA_AMCREST, {'devices': {}, 'cameras': []})
devices = config[DOMAIN]
@@ -149,6 +150,7 @@ def setup(hass, config):
sensors = device.get(CONF_SENSORS)
switches = device.get(CONF_SWITCHES)
stream_source = device[CONF_STREAM_SOURCE]
control_light = device.get(CONF_CONTROL_LIGHT)
# currently aiohttp only works with basic authentication
# only valid for mjpeg streaming
@@ -159,7 +161,7 @@ def setup(hass, config):
hass.data[DATA_AMCREST]['devices'][name] = AmcrestDevice(
api, authentication, ffmpeg_arguments, stream_source,
resolution)
resolution, control_light)
discovery.load_platform(
hass, CAMERA, DOMAIN, {
@@ -245,10 +247,11 @@ class AmcrestDevice:
"""Representation of a base Amcrest discovery device."""
def __init__(self, api, authentication, ffmpeg_arguments,
stream_source, resolution):
stream_source, resolution, control_light):
"""Initialize the entity."""
self.api = api
self.authentication = authentication
self.ffmpeg_arguments = ffmpeg_arguments
self.stream_source = stream_source
self.resolution = resolution
self.control_light = control_light