diff --git a/.coveragerc b/.coveragerc index 7192883b655aac141a8eafd16ff1c48cd414fcb6..94f4352ef89ff850b39f20d6b801f1cd7cee909b 100644 --- a/.coveragerc +++ b/.coveragerc @@ -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 diff --git a/homeassistant/components/device_tracker/icloud.py b/homeassistant/components/device_tracker/icloud.py index a4adaa547bcc94c5693e939c82da8057b7e0f6bc..a617fda941138fe5930941dde498efbaa61fdf33 100644 --- a/homeassistant/components/device_tracker/icloud.py +++ b/homeassistant/components/device_tracker/icloud.py @@ -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 ) diff --git a/requirements_all.txt b/requirements_all.txt index c9835294a20eb0fc26a90877c33c8630ca0f577c..48a127b0f304bb5fd38ff3cf107eebe96a5938f1 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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