8000 Protect sensitive information for Amcrest cameras by tchellomello · Pull Request #10569 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Protect sensitive information for Amcrest cameras #10569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions homeassistant/components/amcrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def setup(hass, config):
"""Set up the Amcrest IP Camera component."""
from amcrest import AmcrestCamera

hass.data[DATA_AMCREST] = {}
amcrest_cams = config[DOMAIN]

for device in amcrest_cams:
Expand Down Expand Up @@ -126,22 +127,34 @@ def setup(hass, config):
else:
authentication = None

hass.data[DATA_AMCREST][name] = AmcrestDevice(
camera, name, authentication, ffmpeg_arguments, stream_source,
resolution)

discovery.load_platform(
hass, 'camera', DOMAIN, {
'device': camera,
CONF_AUTHENTICATION: authentication,
CONF_FFMPEG_ARGUMENTS: ffmpeg_arguments,
CONF_NAME: name,
CONF_RESOLUTION: resolution,
CONF_STREAM_SOURCE: stream_source,
}, config)

if sensors:
discovery.load_platform(
hass, 'sensor', DOMAIN, {
'device': camera,
CONF_NAME: name,
CONF_SENSORS: sensors,
}, config)

return True


class AmcrestDevice(object):
"""Representation of a base Amcrest discovery device."""

def __init__(self, camera, name, authentication, ffmpeg_arguments,
stream_source, resolution):
"""Initialize the entity."""
self.device = camera
self.name = name
self.authentication = authentication
self.ffmpeg_arguments = ffmpeg_arguments
self.stream_source = stream_source
self.resolution = resolution
37 changes: 13 additions & 24 deletions homeassistant/components/camera/amcrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import logging

from homeassistant.components.amcrest import (
STREAM_SOURCE_LIST, TIMEOUT)
DATA_AMCREST, STREAM_SOURCE_LIST, TIMEOUT)
from homeassistant.components.camera import Camera
from homeassistant.components.ffmpeg import DATA_FFMPEG
from homeassistant.const import CONF_NAME
from homeassistant.helpers.aiohttp_client import (
async_get_clientsession, async_aiohttp_proxy_web,
async_aiohttp_proxy_stream)
Expand All @@ -26,40 +27,28 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
if discovery_info is None:
return

device = discovery_info['device']
authentication = discovery_info['authentication']
ffmpeg_arguments = discovery_info['ffmpeg_arguments']
name = discovery_info['name']
resolution = discovery_info['resolution']
stream_source = discovery_info['stream_source']

async_add_devices([
AmcrestCam(hass,
name,
device,
authentication,
ffmpeg_arguments,
stream_source,
resolution)], True)
device_name = discovery_info[CONF_NAME]
amcrest = hass.data[DATA_AMCREST][device_name]

async_add_devices([AmcrestCam(hass, amcrest)], True)

return True


class AmcrestCam(Camera):
"""An implementation of an Amcrest IP camera."""

def __init__(self, hass, name, camera, authentication,
ffmpeg_arguments, stream_source, resolution):
def __init__(self, hass, amcrest):
"""Initialize an Amcrest camera."""
super(AmcrestCam, self).__init__()
self._name = name
self._camera = camera
self._name = amcrest.name
self._camera = amcrest.device
self._base_url = self._camera.get_base_url()
self._ffmpeg = hass.data[DATA_FFMPEG]
self._ffmpeg_arguments = ffmpeg_arguments
self._stream_source = stream_source
self._resolution = resolution
self._token = self._auth = authentication
self._ffmpeg_arguments = amcrest.ffmpeg_arguments
self._stream_source = amcrest.stream_source
self._resolution = amcrest.resolution
self._token = self._auth = amcrest.authentication

def camera_image(self):
"""Return a still image response from the camera."""
Expand Down
13 changes: 7 additions & 6 deletions homeassistant/components/sensor/amcrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from datetime import timedelta
import logging

from homeassistant.components.amcrest import SENSORS
from homeassistant.components.amcrest import DATA_AMCREST, SENSORS
from homeassistant.helpers.entity import Entity
from homeassistant.const import STATE_UNKNOWN
from homeassistant.const import CONF_NAME, CONF_SENSORS, STATE_UNKNOWN

DEPENDENCIES = ['amcrest']

Expand All @@ -25,13 +25,14 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
if discovery_info is None:
return

device = discovery_info['device']
name = discovery_info['name']
sensors = discovery_info['sensors']
device_name = discovery_info[CONF_NAME]
sensors = discovery_info[CONF_SENSORS]
amcrest = hass.data[DATA_AMCREST][device_name]

amcrest_sensors = []
for sensor_type in sensors:
amcrest_sensors.append(AmcrestSensor(name, device, sensor_type))
amcrest_sensors.append(
AmcrestSensor(amcrest.name, amcrest.device, sensor_type))

async_add_devices(amcrest_sensors, True)
return True
Expand Down
0