{"action":"created","comment":{"url":"https://api.github.com/repos/balloob/home-assistant/pulls/comments/53134995","id":53134995,"diff_hunk":"@@ -19,69 +19,126 @@\n CONF_INTERVAL = 'interval'\n DEFAULT_INTERVAL = 8\n \n+# entity attributes\n+ATTR_USERNAME = 'username'\n+ATTR_PASSWORD = 'password'\n+ATTR_ACCOUNTNAME = 'accountname'\n+\n+ICLOUDTRACKERS = {}\n+\n \n def setup_scanner(hass, config, see):\n     \"\"\" Set up the iCloud Scanner. \"\"\"\n-    from pyicloud import PyiCloudService\n-    from pyicloud.exceptions import PyiCloudFailedLoginException\n-    from pyicloud.exceptions import PyiCloudNoDevicesException\n \n     # Get the username and password from the configuration\n     username = config.get(CONF_USERNAME)\n     password = config.get(CONF_PASSWORD)\n+    name = config.get(CONF_NAME, username)\n \n-    if username is None or password is None:\n-        _LOGGER.error('Must specify a username and password')\n-        return False\n+    iclouddevice = Icloud(hass, username, password, name)\n+    ICLOUDTRACKERS[name] = iclouddevice\n \n-    try:\n-        _LOGGER.info('Logging into iCloud Account')\n-        # Attempt the login to iCloud\n-        api = PyiCloudService(username,\n-                              password,\n-                              verify=True)\n-    except PyiCloudFailedLoginException as error:\n-        _LOGGER.exception('Error logging into iCloud Service: %s', error)\n-        return False\n+    def lost_iphone(call):\n+        \"\"\" Calls the lost iphone function if the device is found \"\"\"\n+        accountname = call.data.get('accountname')\n+        devicename = call.data.get('devicename')\n+        if accountname in ICLOUDTRACKERS:\n+            ICLOUDTRACKERS[accountname].lost_iphone(devicename)\n \n-    def keep_alive(now):\n-        \"\"\" Keeps authenticating iCloud connection. \"\"\"\n-        api.authenticate()\n-        _LOGGER.info(\"Authenticate against iCloud\")\n+    hass.services.register('device_tracker', 'lost_iphone',\n+                           lost_iphone)\n \n-    track_utc_time_change(hass, keep_alive, second=0)\n+    def update_icloud(call):\n+        \"\"\" Calls the update function of an icloud account \"\"\"\n+        accountname = call.data.get('accountname')\n+        if accountname in ICLOUDTRACKERS:\n+            ICLOUDTRACKERS[accountname].update_icloud(see)\n \n-    def update_icloud(now):\n-        \"\"\" Authenticate against iCloud and scan for devices. \"\"\"\n-        try:\n-            # The session timeouts if we are not using it so we\n-            # have to re-authenticate. This will send an email.\n-            api.authenticate()\n-            # Loop through every device registered with the iCloud account\n-            for device in api.devices:\n-                status = device.status()\n-                location = device.location()\n-                # If the device has a location add it. If not do nothing\n-                if location:\n-                    see(\n-                        dev_id=re.sub(r\"(\\s|\\W|')\",\n-                                      '',\n-                                      status['name']),\n-                        host_name=status['name'],\n-                        gps=(location['latitude'], location['longitude']),\n-                        battery=status['batteryLevel']*100,\n-                        gps_accuracy=location['horizontalAccuracy']\n-                    )\n-                else:\n-                    # No location found for the device so continue\n-                    continue\n-        except PyiCloudNoDevicesException:\n-            _LOGGER.info('No iCloud Devices found!')\n+    hass.services.register('device_tracker',\n+                           'update_icloud', update_icloud)\n+    iclouddevice.update_icloud(see)\n \n     track_utc_time_change(\n-        hass, update_icloud,\n+        hass, iclouddevice.update_icloud(see),","path":"homeassistant/components/device_tracker/icloud.py","position":100,"original_position":100,"commit_id":"9fd1efc8b58c06ebb8a179b68195ab79a7816b16","original_commit_id":"9fd1efc8b58c06ebb8a179b68195ab79a7816b16","user":{"login":"balloob","id":1444314,"avatar_url":"https://avatars.githubusercontent.com/u/1444314?v=3","gravatar_id":"","url":"https://api.github.com/users/balloob","html_url":"https://github.com/balloob","followers_url":"https://api.github.com/users/balloob/followers","following_url":"https://api.github.com/users/balloob/following{/other_user}","gists_url":"https://api.github.com/users/balloob/gists{/gist_id}","starred_url":"https://api.github.com/users/balloob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/balloob/subscriptions","organizations_url":"https://api.github.com/users/balloob/orgs","repos_url":"https://api.github.com/users/balloob/repos","events_url":"https://api.github.com/users/balloob/events{/privacy}","received_events_url":"https://api.github.com/users/balloob/received_events","type":"User","site_admin":false},"body":"Icloud devices are no longer polled and I'm pretty sure you're getting\nexceptions whenever it tries to poll\n\nOn Wed, Feb 17, 2016, 00:31 Bart274 <notifications@github.com> wrote:\n\n> In homeassistant/components/device_tracker/icloud.py\n> <https://github.com/balloob/home-assistant/pull/1107#discussion_r53133167>\n> :\n>\n> >\n> >      track_utc_time_change(\n> > -        hass, update_icloud,\n> > +        hass, iclouddevice.update_icloud(see),\n>\n> What do you mean I need to pass a callback? Any example?\n> I'm running this version in my installation and everything works great, so\n> I am testing it locally\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/balloob/home-assistant/pull/1107/files#r53133167>.\n>\n","created_at":"2016-02-17T08:52:29Z","updated_at":"2016-02-17T08:52:29Z","html_url":"https://github.com/balloob/home-assistant/pull/1107#discussion_r53134995","pull_request_url":"https://api.github.com/repos/balloob/home-assistant/pulls/1107","_links":{"self":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/comments/53134995"},"html":{"href":"https://github.com/balloob/home-assistant/pull/1107#discussion_r53134995"},"pull_request":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/1107"}}},"pull_request":{"url":"https://api.github.com/repos/balloob/home-assistant/pulls/1107","id":58110328,"html_url":"https://github.com/balloob/home-assistant/pull/1107","diff_url":"https://github.com/balloob/home-assistant/pull/1107.diff","patch_url":"https://github.com/balloob/home-assistant/pull/1107.patch","issue_url":"https://api.github.com/repos/balloob/home-assistant/issues/1107","number":1107,"state":"open","locked":false,"title":"Add service to update icloud tracker whenever we want","user":{"login":"Bart274","id":1118630,"avatar_url":"https://avatars.githubusercontent.com/u/1118630?v=3","gravatar_id":"","url":"https://api.github.com/users/Bart274","html_url":"https://github.com/Bart274","followers_url":"https://api.github.com/users/Bart274/followers","following_url":"https://api.github.com/users/Bart274/following{/other_user}","gists_url":"https://api.github.com/users/Bart274/gists{/gist_id}","starred_url":"https://api.github.com/users/Bart274/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bart274/subscriptions","organizations_url":"https://api.github.com/users/Bart274/orgs","repos_url":"https://api.github.com/users/Bart274/repos","events_url":"https://api.github.com/users/Bart274/events{/privacy}","received_events_url":"https://api.github.com/users/Bart274/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-03T09:22:07Z","updated_at":"2016-02-17T08:52:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"06b544d256ebe5e75c5c444d87feb5f156055685","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/balloob/home-assistant/pulls/1107/commits","review_comments_url":"https://api.github.com/repos/balloob/home-assistant/pulls/1107/comments","review_comment_url":"https://api.github.com/repos/balloob/home-assistant/pulls/comments{/number}","comments_url":"https://api.github.com/repos/balloob/home-assistant/issues/1107/comments","statuses_url":"https://api.github.com/repos/balloob/home-assistant/statuses/9fd1efc8b58c06ebb8a179b68195ab79a7816b16","head":{"label":"Bart274:dev","ref":"dev","sha":"9fd1efc8b58c06ebb8a179b68195ab79a7816b16","user":{"login":"Bart274","id":1118630,"avatar_url":"https://avatars.githubusercontent.com/u/1118630?v=3","gravatar_id":"","url":"https://api.github.com/users/Bart274","html_url":"https://github.com/Bart274","followers_url":"https://api.github.com/users/Bart274/followers","following_url":"https://api.github.com/users/Bart274/following{/other_user}","gists_url":"https://api.github.com/users/Bart274/gists{/gist_id}","starred_url":"https://api.github.com/users/Bart274/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bart274/subscriptions","organizations_url":"https://api.github.com/users/Bart274/orgs","repos_url":"https://api.github.com/users/Bart274/repos","events_url":"https://api.github.com/users/Bart274/events{/privacy}","received_events_url":"https://api.github.com/users/Bart274/received_events","type":"User","site_admin":false},"repo":{"id":50988428,"name":"home-assistant","full_name":"Bart274/home-assistant","owner":{"login":"Bart274","id":1118630,"avatar_url":"https://avatars.githubusercontent.com/u/1118630?v=3","gravatar_id":"","url":"https://api.github.com/users/Bart274","html_url":"https://github.com/Bart274","followers_url":"https://api.github.com/users/Bart274/followers","following_url":"https://api.github.com/users/Bart274/following{/other_user}","gists_url":"https://api.github.com/users/Bart274/gists{/gist_id}","starred_url":"https://api.github.com/users/Bart274/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bart274/subscriptions","organizations_url":"https://api.github.com/users/Bart274/orgs","repos_url":"https://api.github.com/users/Bart274/repos","events_url":"https://api.github.com/users/Bart274/events{/privacy}","received_events_url":"https://api.github.com/users/Bart274/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Bart274/home-assistant","description":":house_with_garden: Open-source home automation platform running on Python 3","fork":true,"url":"https://api.github.com/repos/Bart274/home-assistant","forks_url":"https://api.github.com/repos/Bart274/home-assistant/forks","keys_url":"https://api.github.com/repos/Bart274/home-assistant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Bart274/home-assistant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Bart274/home-assistant/teams","hooks_url":"https://api.github.com/repos/Bart274/home-assistant/hooks","issue_events_url":"https://api.github.com/repos/Bart274/home-assistant/issues/events{/number}","events_url":"https://api.github.com/repos/Bart274/home-assistant/events","assignees_url":"https://api.github.com/repos/Bart274/home-assistant/assignees{/user}","branches_url":"https://api.github.com/repos/Bart274/home-assistant/branches{/branch}","tags_url":"https://api.github.com/repos/Bart274/home-assistant/tags","blobs_url":"https://api.github.com/repos/Bart274/home-assistant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Bart274/home-assistant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Bart274/home-assistant/git/refs{/sha}","trees_url":"https://api.github.com/repos/Bart274/home-assistant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Bart274/home-assistant/statuses/{sha}","languages_url":"https://api.github.com/repos/Bart274/home-assistant/languages","stargazers_url":"https://api.github.com/repos/Bart274/home-assistant/stargazers","contributors_url":"https://api.github.com/repos/Bart274/home-assistant/contributors","subscribers_url":"https://api.github.com/repos/Bart274/home-assistant/subscribers","subscription_url":"https://api.github.com/repos/Bart274/home-assistant/subscription","commits_url":"https://api.github.com/repos/Bart274/home-assistant/commits{/sha}","git_commits_url":"https://api.github.com/repos/Bart274/home-assistant/git/commits{/sha}","comments_url":"https://api.github.com/repos/Bart274/home-assistant/comments{/number}","issue_comment_url":"https://api.github.com/repos/Bart274/home-assistant/issues/comments{/number}","contents_url":"https://api.github.com/repos/Bart274/home-assistant/contents/{+path}","compare_url":"https://api.github.com/repos/Bart274/home-assistant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Bart274/home-assistant/merges","archive_url":"https://api.github.com/repos/Bart274/home-assistant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Bart274/home-assistant/downloads","issues_url":"https://api.github.com/repos/Bart274/home-assistant/issues{/number}","pulls_url":"https://api.github.com/repos/Bart274/home-assistant/pulls{/number}","milestones_url":"https://api.github.com/repos/Bart274/home-assistant/milestones{/number}","notifications_url":"https://api.github.com/repos/Bart274/home-assistant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Bart274/home-assistant/labels{/name}","releases_url":"https://api.github.com/repos/Bart274/home-assistant/releases{/id}","deployments_url":"https://api.github.com/repos/Bart274/home-assistant/deployments","created_at":"2016-02-03T09:21:05Z","updated_at":"2016-02-03T09:21:07Z","pushed_at":"2016-02-17T08:24:32Z","git_url":"git://github.com/Bart274/home-assistant.git","ssh_url":"git@github.com:Bart274/home-assistant.git","clone_url":"https://github.com/Bart274/home-assistant.git","svn_url":"https://github.com/Bart274/home-assistant","homepage":"https://home-assistant.io","size":39557,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"balloob:dev","ref":"dev","sha":"f5e736d271e0141d57873d20435ce02e3ef705a5","user":{"login":"balloob","id":1444314,"avatar_url":"https://avatars.githubusercontent.com/u/1444314?v=3","gravatar_id":"","url":"https://api.github.com/users/balloob","html_url":"https://github.com/balloob","followers_url":"https://api.github.com/users/balloob/followers","following_url":"https://api.github.com/users/balloob/following{/other_user}","gists_url":"https://api.github.com/users/balloob/gists{/gist_id}","starred_url":"https://api.github.com/users/balloob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/balloob/subscriptions","organizations_url":"https://api.github.com/users/balloob/orgs","repos_url":"https://api.github.com/users/balloob/repos","events_url":"https://api.github.com/users/balloob/events{/privacy}","received_events_url":"https://api.github.com/users/balloob/received_events","type":"User","site_admin":false},"repo":{"id":12888993,"name":"home-assistant","full_name":"balloob/home-assistant","owner":{"login":"balloob","id":1444314,"avatar_url":"https://avatars.githubusercontent.com/u/1444314?v=3","gravatar_id":"","url":"https://api.github.com/users/balloob","html_url":"https://github.com/balloob","followers_url":"https://api.github.com/users/balloob/followers","following_url":"https://api.github.com/users/balloob/following{/other_user}","gists_url":"https://api.github.com/users/balloob/gists{/gist_id}","starred_url":"https://api.github.com/users/balloob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/balloob/subscriptions","organizations_url":"https://api.github.com/users/balloob/orgs","repos_url":"https://api.github.com/users/balloob/repos","events_url":"https://api.github.com/users/balloob/events{/privacy}","received_events_url":"https://api.github.com/users/balloob/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/balloob/home-assistant","description":":house_with_garden: Open-source home automation platform running on Python 3","fork":false,"url":"https://api.github.com/repos/balloob/home-assistant","forks_url":"https://api.github.com/repos/balloob/home-assistant/forks","keys_url":"https://api.github.com/repos/balloob/home-assistant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/balloob/home-assistant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/balloob/home-assistant/teams","hooks_url":"https://api.github.com/repos/balloob/home-assistant/hooks","issue_events_url":"https://api.github.com/repos/balloob/home-assistant/issues/events{/number}","events_url":"https://api.github.com/repos/balloob/home-assistant/events","assignees_url":"https://api.github.com/repos/balloob/home-assistant/assignees{/user}","branches_url":"https://api.github.com/repos/balloob/home-assistant/branches{/branch}","tags_url":"https://api.github.com/repos/balloob/home-assistant/tags","blobs_url":"https://api.github.com/repos/balloob/home-assistant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/balloob/home-assistant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/balloob/home-assistant/git/refs{/sha}","trees_url":"https://api.github.com/repos/balloob/home-assistant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/balloob/home-assistant/statuses/{sha}","languages_url":"https://api.github.com/repos/balloob/home-assistant/languages","stargazers_url":"https://api.github.com/repos/balloob/home-assistant/stargazers","contributors_url":"https://api.github.com/repos/balloob/home-assistant/contributors","subscribers_url":"https://api.github.com/repos/balloob/home-assistant/subscribers","subscription_url":"https://api.github.com/repos/balloob/home-assistant/subscription","commits_url":"https://api.github.com/repos/balloob/home-assistant/commits{/sha}","git_commits_url":"https://api.github.com/repos/balloob/home-assistant/git/commits{/sha}","comments_url":"https://api.github.com/repos/balloob/home-assistant/comments{/number}","issue_comment_url":"https://api.github.com/repos/balloob/home-assistant/issues/comments{/number}","contents_url":"https://api.github.com/repos/balloob/home-assistant/contents/{+path}","compare_url":"https://api.github.com/repos/balloob/home-assistant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/balloob/home-assistant/merges","archive_url":"https://api.github.com/repos/balloob/home-assistant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/balloob/home-assistant/downloads","issues_url":"https://api.github.com/repos/balloob/home-assistant/issues{/number}","pulls_url":"https://api.github.com/repos/balloob/home-assistant/pulls{/number}","milestones_url":"https://api.github.com/repos/balloob/home-assistant/milestones{/number}","notifications_url":"https://api.github.com/repos/balloob/home-assistant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/balloob/home-assistant/labels{/name}","releases_url":"https://api.github.com/repos/balloob/home-assistant/releases{/id}","deployments_url":"https://api.github.com/repos/balloob/home-assistant/deployments","created_at":"2013-09-17T07:29:48Z","updated_at":"2016-02-17T04:01:34Z","pushed_at":"2016-02-17T08:23:35Z","git_url":"git://github.com/balloob/home-assistant.git","ssh_url":"git@github.com:balloob/home-assistant.git","clone_url":"https://github.com/balloob/home-assistant.git","svn_url":"https://github.com/balloob/home-assistant","homepage":"https://home-assistant.io","size":44480,"stargazers_count":2741,"watchers_count":2741,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":446,"mirror_url":null,"open_issues_count":164,"forks":446,"open_issues":164,"watchers":2741,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/1107"},"html":{"href":"https://github.com/balloob/home-assistant/pull/1107"},"issue":{"href":"https://api.github.com/repos/balloob/home-assistant/issues/1107"},"comments":{"href":"https://api.github.com/repos/balloob/home-assistant/issues/1107/comments"},"review_comments":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/1107/comments"},"review_comment":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/1107/commits"},"statuses":{"href":"https://api.github.com/repos/balloob/home-assistant/statuses/9fd1efc8b58c06ebb8a179b68195ab79a7816b16"}}}}