Add Verisure smartcam capture service (#4559)

* Add verisure capture as service

* docstyle
pull/4738/merge
John Arild Berentsen 2016-12-06 02:51:58 +01:00 committed by Paulus Schoutsen
parent 1ae8256ffd
commit fa8bc0a36c
2 changed files with 36 additions and 0 deletions

View File

@ -144,3 +144,12 @@ openalpr:
restart:
description: Restart ffmpeg process of device.
verisure:
capture_smartcam:
description: Capture a new image from a smartcam.
fields:
device_serial:
description: The serial number of the smartcam you want to capture an image from.
example: '2DEU AT5Z'

View File

@ -7,6 +7,7 @@ https://home-assistant.io/components/verisure/
import logging
import threading
import time
import os.path
from datetime import timedelta
import voluptuous as vol
@ -14,12 +15,14 @@ import voluptuous as vol
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.helpers import discovery
from homeassistant.util import Throttle
import homeassistant.config as conf_util
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['vsure==0.11.1']
_LOGGER = logging.getLogger(__name__)
ATTR_DEVICE_SERIAL = 'device_serial'
CONF_ALARM = 'alarm'
CONF_CODE_DIGITS = 'code_digits'
CONF_HYDROMETERS = 'hygrometers'
@ -29,6 +32,7 @@ CONF_SMARTPLUGS = 'smartplugs'
CONF_THERMOMETERS = 'thermometers'
CONF_SMARTCAM = 'smartcam'
DOMAIN = 'verisure'
SERVICE_CAPTURE_SMARTCAM = 'capture_smartcam'
HUB = None
@ -47,6 +51,10 @@ CONFIG_SCHEMA = vol.Schema({
}),
}, extra=vol.ALLOW_EXTRA)
CAPTURE_IMAGE_SCHEMA = vol.Schema({
vol.Required(ATTR_DEVICE_SERIAL): cv.string
})
def setup(hass, config):
"""Setup the Verisure component."""
@ -60,6 +68,20 @@ def setup(hass, config):
'camera'):
discovery.load_platform(hass, component, DOMAIN, {}, config)
descriptions = conf_util.load_yaml_config_file(
os.path.join(os.path.dirname(__file__), 'services.yaml'))
def capture_smartcam(service):
"""Capture a new picture from a smartcam."""
device_id = service.data.get(ATTR_DEVICE_SERIAL)
HUB.smartcam_capture(device_id)
_LOGGER.debug('Capturing new image from %s', ATTR_DEVICE_SERIAL)
hass.services.register(DOMAIN, SERVICE_CAPTURE_SMARTCAM,
capture_smartcam,
descriptions[DOMAIN][SERVICE_CAPTURE_SMARTCAM],
schema=CAPTURE_IMAGE_SCHEMA)
return True
@ -150,6 +172,11 @@ class VerisureHub(object):
self.smartcam_dict = self.my_pages.smartcam.get_imagelist()
_LOGGER.debug('New dict: %s', self.smartcam_dict)
@Throttle(timedelta(seconds=30))
def smartcam_capture(self, device_id):
"""Capture a new image from a smartcam."""
self.my_pages.smartcam.capture(device_id)
@property
def available(self):
"""Return True if hub is available."""