Tweak iCloud device tracker

This commit is contained in:
Paulus Schoutsen 2015-12-14 21:39:48 -08:00
parent 79c92cd0c4
commit 2e0042adb0
3 changed files with 26 additions and 13 deletions

View File

@ -41,6 +41,7 @@ omit =
homeassistant/components/device_tracker/ddwrt.py
homeassistant/components/device_tracker/fritz.py
homeassistant/components/device_tracker/geofancy.py
homeassistant/components/device_tracker/icloud.py
homeassistant/components/device_tracker/luci.py
homeassistant/components/device_tracker/ubus.py
homeassistant/components/device_tracker/netgear.py

View File

@ -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
)

View File

@ -9,6 +9,9 @@ jinja2>=2.8
# homeassistant.components.arduino
PyMata==2.07a
# homeassistant.components.device_tracker.icloud
https://github.com/picklepete/pyicloud/archive/80f6cd6decc950514b8dc43b30c5bded81b34d5f.zip#pyicloud==0.8.0
# homeassistant.components.device_tracker.netgear
pynetgear==0.3
@ -177,6 +180,3 @@ https://github.com/persandstrom/python-verisure/archive/9873c4527f01b1ba1f72ae60
# homeassistant.components.zwave
pydispatcher==2.0.5
# homeassistant.sensor.icloud
https://github.com/picklepete/pyicloud/archive/80f6cd6decc950514b8dc43b30c5bded81b34d5f.zip#pyicloud==0.8.0