* Added camera service calls to arm/disarm the cameras. Entity id is optional so that with a single call we can arm all the cameras or specify a particular entity id to arm if applicable and possible in that camera type. * Added camera service calls to arm/disarm the cameras. Entity id is optional so that with a single call we can arm all the cameras or specify a particular entity id to arm if applicable and possible in that camera type. * Added camera service calls to arm/disarm the cameras. Entity id is optional so that with a single call we can arm all the cameras or specify a particular entity id to arm if applicable and possible in that camera type. * Fixed the spaces and indentation related issues that houndci found * Fixed the spaces and indentation related issues that houndci found * Missed the const file which has the macros defined. * Fixed the CI build error * Fixed the CI build error because of unused variable in exception case * Updating the arlo code based on comment from @balloob. Changed the arm and disarm to enable_motion_detection and disable_motion_detection respectively. Similarly fixed the AttributeError handling. Added dummy code to the demo camera also. Moved out the definitions in const.py into the camera __init__ file * Fixed the comments posted by houndci-bot * Fixed the comments posted by houndci-bot * Fixed the comments posted by houndci-bot * Fixed the comments posted by travis-ci integration bot * Fixed the comments posted by travis-ci integration bot * Fixed the comments posted by travis-ci integration bot for demo.py: expected 2 lines, found 1 * Updated code in camera __init__.py to use the get function instead of directly calling the member in the structure. * Updated code in camera __init__.py * Posting the updated code for PR based on @balloob's suggestions/recommendations * Removed the arlo reference from demo code. Copy-paste error * Removed the unused import found by hound bot * Expected 2 lines before function, but found only 1. * Based on @balloob's comments, moved these constants to the camera/arlo.py * Added test_demo.py to test the motion enabled and motion disabled in camera component * Fixing issues found by houndci-bot * Fixing issues found by houndci-bot * Fixing the code as per @balloob's suggestions * Fixing the code as per @balloob's suggestions * Fixing the test_demo failure. Tried to rewrite a base function to enable the motion in __init__.py and missed to add it to as a job. * Fixing the hound bot comment * Update arlo.py * Update arlo.py
117 lines
3.4 KiB
Python
117 lines
3.4 KiB
Python
"""
|
|
This component provides basic support for Netgear Arlo IP cameras.
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
https://home-assistant.io/components/camera.arlo/
|
|
"""
|
|
import asyncio
|
|
import logging
|
|
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.helpers import config_validation as cv
|
|
from homeassistant.helpers.aiohttp_client import async_aiohttp_proxy_stream
|
|
from homeassistant.components.arlo import DEFAULT_BRAND, DATA_ARLO
|
|
from homeassistant.components.camera import Camera, PLATFORM_SCHEMA
|
|
from homeassistant.components.ffmpeg import DATA_FFMPEG
|
|
|
|
DEPENDENCIES = ['arlo', 'ffmpeg']
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
CONF_FFMPEG_ARGUMENTS = 'ffmpeg_arguments'
|
|
ARLO_MODE_ARMED = 'armed'
|
|
ARLO_MODE_DISARMED = 'disarmed'
|
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|
vol.Optional(CONF_FFMPEG_ARGUMENTS): cv.string,
|
|
})
|
|
|
|
|
|
@asyncio.coroutine
|
|
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|
"""Set up an Arlo IP Camera."""
|
|
arlo = hass.data.get(DATA_ARLO)
|
|
if not arlo:
|
|
return False
|
|
|
|
cameras = []
|
|
for camera in arlo.cameras:
|
|
cameras.append(ArloCam(hass, camera, config))
|
|
|
|
async_add_devices(cameras, True)
|
|
|
|
|
|
class ArloCam(Camera):
|
|
"""An implementation of a Netgear Arlo IP camera."""
|
|
|
|
def __init__(self, hass, camera, device_info):
|
|
"""Initialize an Arlo camera."""
|
|
super().__init__()
|
|
self._camera = camera
|
|
self._base_stn = hass.data['arlo'].base_stations[0]
|
|
self._name = self._camera.name
|
|
self._motion_status = False
|
|
self._ffmpeg = hass.data[DATA_FFMPEG]
|
|
self._ffmpeg_arguments = device_info.get(CONF_FFMPEG_ARGUMENTS)
|
|
|
|
def camera_image(self):
|
|
"""Return a still image response from the camera."""
|
|
return self._camera.last_image
|
|
|
|
@asyncio.coroutine
|
|
def handle_async_mjpeg_stream(self, request):
|
|
"""Generate an HTTP MJPEG stream from the camera."""
|
|
from haffmpeg import CameraMjpeg
|
|
video = self._camera.last_video
|
|
if not video:
|
|
return
|
|
|
|
stream = CameraMjpeg(self._ffmpeg.binary, loop=self.hass.loop)
|
|
yield from stream.open_camera(
|
|
video.video_url, extra_cmd=self._ffmpeg_arguments)
|
|
|
|
yield from async_aiohttp_proxy_stream(
|
|
self.hass, request, stream,
|
|
'multipart/x-mixed-replace;boundary=ffserver')
|
|
yield from stream.close()
|
|
|
|
@property
|
|
def name(self):
|
|
"""Return the name of this camera."""
|
|
return self._name
|
|
|
|
@property
|
|
def model(self):
|
|
"""Camera model."""
|
|
return self._camera.model_id
|
|
|
|
@property
|
|
def brand(self):
|
|
"""Camera brand."""
|
|
return DEFAULT_BRAND
|
|
|
|
@property
|
|
def should_poll(self):
|
|
"""Camera should poll periodically."""
|
|
return True
|
|
|
|
@property
|
|
def motion_detection_enabled(self):
|
|
"""Camera Motion Detection Status."""
|
|
return self._motion_status
|
|
|
|
def set_base_station_mode(self, mode):
|
|
"""Set the mode in the base station."""
|
|
self._base_stn.mode = mode
|
|
|
|
def enable_motion_detection(self):
|
|
"""Enable the Motion detection in base station (Arm)."""
|
|
self._motion_status = True
|
|
self.set_base_station_mode(ARLO_MODE_ARMED)
|
|
|
|
def disable_motion_detection(self):
|
|
"""Disable the motion detection in base station (Disarm)."""
|
|
self._motion_status = False
|
|
self.set_base_station_mode(ARLO_MODE_DISARMED)
|