2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Ring Doorbell/Chimes."""
|
2017-03-31 15:53:56 +00:00
|
|
|
import logging
|
2018-02-11 17:20:28 +00:00
|
|
|
|
2019-02-14 21:09:22 +00:00
|
|
|
from requests.exceptions import ConnectTimeout, HTTPError
|
2017-03-31 15:53:56 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2019-02-14 21:09:22 +00:00
|
|
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
2018-02-11 17:20:28 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
2017-03-31 15:53:56 +00:00
|
|
|
|
2018-10-29 22:27:12 +00:00
|
|
|
REQUIREMENTS = ['ring_doorbell==0.2.2']
|
2017-03-31 15:53:56 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-02-14 21:09:22 +00:00
|
|
|
ATTRIBUTION = "Data provided by Ring.com"
|
2017-03-31 15:53:56 +00:00
|
|
|
|
|
|
|
NOTIFICATION_ID = 'ring_notification'
|
2017-11-25 11:15:12 +00:00
|
|
|
NOTIFICATION_TITLE = 'Ring Setup'
|
2017-03-31 15:53:56 +00:00
|
|
|
|
2017-10-21 14:08:40 +00:00
|
|
|
DATA_RING = 'ring'
|
2017-03-31 15:53:56 +00:00
|
|
|
DOMAIN = 'ring'
|
|
|
|
DEFAULT_CACHEDB = '.ring_cache.pickle'
|
|
|
|
DEFAULT_ENTITY_NAMESPACE = 'ring'
|
|
|
|
|
|
|
|
CONFIG_SCHEMA = vol.Schema({
|
|
|
|
DOMAIN: vol.Schema({
|
|
|
|
vol.Required(CONF_USERNAME): cv.string,
|
|
|
|
vol.Required(CONF_PASSWORD): cv.string,
|
|
|
|
}),
|
|
|
|
}, extra=vol.ALLOW_EXTRA)
|
|
|
|
|
|
|
|
|
|
|
|
def setup(hass, config):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up the Ring component."""
|
2017-03-31 15:53:56 +00:00
|
|
|
conf = config[DOMAIN]
|
2018-03-15 20:49:49 +00:00
|
|
|
username = conf[CONF_USERNAME]
|
|
|
|
password = conf[CONF_PASSWORD]
|
2017-03-31 15:53:56 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
from ring_doorbell import Ring
|
|
|
|
|
|
|
|
cache = hass.config.path(DEFAULT_CACHEDB)
|
|
|
|
ring = Ring(username=username, password=password, cache_file=cache)
|
|
|
|
if not ring.is_connected:
|
|
|
|
return False
|
|
|
|
hass.data['ring'] = ring
|
|
|
|
except (ConnectTimeout, HTTPError) as ex:
|
|
|
|
_LOGGER.error("Unable to connect to Ring service: %s", str(ex))
|
2017-07-16 19:39:38 +00:00
|
|
|
hass.components.persistent_notification.create(
|
|
|
|
'Error: {}<br />'
|
2017-03-31 15:53:56 +00:00
|
|
|
'You will need to restart hass after fixing.'
|
|
|
|
''.format(ex),
|
|
|
|
title=NOTIFICATION_TITLE,
|
|
|
|
notification_id=NOTIFICATION_ID)
|
|
|
|
return False
|
|
|
|
return True
|