Tweak iCloud device tracker

This commit is contained in:
Paulus Schoutsen committed 2015-12-14 21:39:48 -08:00
1 parent 79c92cd0c4
commit 2e0042adb0
3 files changed
+26 -13

No files matched your search

@@ -20,14 +20,15 @@ import re
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
from homeassistant.helpers.event import track_utc_time_change
SCAN_INTERVAL = 1800
_LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['https://github.com/picklepete/pyicloud/archive/'
'80f6cd6decc950514b8dc43b30c5bded81b34d5f.zip'
'#pyicloud==0.8.0']
CONF_INTERVAL = 'interval'
DEFAULT_INTERVAL = 8
def setup_scanner(hass, config, see):
"""
@@ -38,8 +39,12 @@ def setup_scanner(hass, config, see):
from pyicloud.exceptions import PyiCloudNoDevicesException
# Get the username and password from the configuration
username = config[CONF_USERNAME]
password = config[CONF_PASSWORD]
username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
if username is None or password is None:
_LOGGER.error('Must specify a username and password')
return
try:
_LOGGER.info('Logging into iCloud Account')
@@ -48,11 +53,18 @@ def setup_scanner(hass, config, see):
password,
verify=True)
except PyiCloudFailedLoginException as error:
_LOGGER.exception(
'Error logging into iCloud Service: %s' % error
)
_LOGGER.exception('Error logging into iCloud Service: %s', error)
return
def keep_alive(now):
"""
Keeps authenticating icloud connection
"""
api.authenticate()
_LOGGER.info("Authenticate against iCloud.")
track_utc_time_change(hass, keep_alive, second=0)
def update_icloud(now):
"""
Authenticate against iCloud and scan for devices.
@@ -83,7 +95,7 @@ def setup_scanner(hass, config, see):
_LOGGER.info('No iCloud Devices found!')
track_utc_time_change(
hass,
update_icloud,
second=range(0, 60, SCAN_INTERVAL)
hass, update_icloud,
minute=range(0, 60, config.get(CONF_INTERVAL, DEFAULT_INTERVAL)),
second=0
)