forked from evanjd/hass-logi-circle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logi.py
63 lines (49 loc) · 1.74 KB
/
logi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Support for Logi Circle cameras
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/logi/
"""
import logging
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
from homeassistant.components.camera import CAMERA_SERVICE_SCHEMA
REQUIREMENTS = ['logi_circle==0.1.1']
_LOGGER = logging.getLogger(__name__)
CONF_ATTRIBUTION = "Data provided by circle.logi.com"
NOTIFICATION_ID = 'logi_notification'
NOTIFICATION_TITLE = 'Logi Setup'
DATA_LOGI = 'logi'
DOMAIN = 'logi'
DEFAULT_CACHEDB = '.logi_cache.pickle'
DEFAULT_ENTITY_NAMESPACE = 'logi'
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
}),
}, extra=vol.ALLOW_EXTRA)
async def async_setup(hass, config):
"""Set up the Logi component."""
conf = config[DOMAIN]
username = conf[CONF_USERNAME]
password = conf[CONF_PASSWORD]
try:
from logi_circle import Logi
from logi_circle.exception import BadLogin
cache = hass.config.path(DEFAULT_CACHEDB)
logi = Logi(username=username, password=password, cache_file=cache)
await logi.login()
if not logi.is_connected:
return False
hass.data['logi'] = logi
except BadLogin as ex:
_LOGGER.error('Unable to connect to Logi API: %s', str(ex))
hass.components.persistent_notification.create(
'Error: {}<br />'
'You will need to restart hass after fixing.'
''.format(ex),
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID)
return False
return True