{"action":"created","comment":{"url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments/154363821","pull_request_review_id":80518670,"id":154363821,"diff_hunk":"@@ -0,0 +1,145 @@\n+\"\"\"\n+Support for the Life360 platform.\n+\n+For more details about this platform, please refer to the documentation at\n+TODO\n+\"\"\"\n+import logging\n+\n+#making http requests happening\n+import requests\n+\n+import voluptuous as vol\n+\n+from homeassistant.components.device_tracker import PLATFORM_SCHEMA\n+from homeassistant.const import CONF_USERNAME, CONF_PASSWORD\n+import homeassistant.helpers.config_validation as cv\n+from homeassistant.helpers.event import track_utc_time_change\n+from homeassistant.util import slugify\n+\n+_LOGGER = logging.getLogger(__name__)\n+\n+PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({\n+    vol.Required(CONF_USERNAME): cv.string,\n+    vol.Required(CONF_PASSWORD): cv.string\n+})\n+\n+\n+def setup_scanner(hass, config: dict, see, discovery_info=None):\n+    \"\"\"Validate the configuration and return a Life360 scanner.\"\"\"\n+    Life360Scanner(hass, config, see)\n+    return True\n+\n+\n+class Life360Scanner(object):\n+    \"\"\"A class representing a Life360 scanner.\"\"\"\n+\n+    def __init__(self, hass, config: dict, see) -> None:\n+        \"\"\"Initialize the Life360 scanner.\"\"\"\n+\n+        self.hass = hass\n+        self.see = see\n+\n+        self.username = config.get(CONF_USERNAME)\n+        self.password = config.get(CONF_PASSWORD)\n+\n+        self._update_info()\n+\n+        track_utc_time_change(\n+            self.hass, self._update_info, second=range(0, 60, 30))\n+    \n+    def get_members(self):\n+        #reset member to nothing\n+        self.members = []\n+\n+        #get bearer token\n+        url = 'https://api.life360.com/v3/oauth2/token.json'\n+        payload = payload = {'grant_type': 'password', 'username': self.username, 'password': self.password}\n+        headers = {'Authorization': 'Basic cFJFcXVnYWJSZXRyZTRFc3RldGhlcnVmcmVQdW1hbUV4dWNyRUh1YzptM2ZydXBSZXRSZXN3ZXJFQ2hBUHJFOTZxYWtFZHI0Vg=='}\n+        r = requests.post(url, data=payload , headers=headers)\n+\n+        #check if we have valid response\n+        if r.status_code != 200:\n+            _LOGGER.error(\"Didn't get a good http response while logging in: %s\", r.status_code)\n+            return None\n+\n+        #hopefully this is working\n+        try:\n+            data = r.json()\n+            self.access_token = data['access_token']\n+        except:\n+            _LOGGER.error(\"Failed to Login\")\n+            self.success_init = False\n+\n+        _LOGGER.info(\"Scanning\")\n+\n+        \"\"\"\n+        Life360 has the following hierarchy to list devices\n+        Account -> Circles -> Members enrolled in Circle\n+        \"\"\"\n+        #first retrieve the circles\n+        url = \"https://api.life360.com/v3/circles.json\"\n+        headers = {'Content-Type': 'application/json','Authorization': 'Bearer ' + self.access_token}\n+        r = requests.get(url, headers=headers)\n+\n+        #check if we have valid response\n+        if r.status_code != 200:\n+            _LOGGER.error(\"Didn't get a good http response while getting circles: %s\", r.status_code)\n+            return None\n+\n+        #hopefully this is working\n+        try:\n+            #put data in json form\n+            self.circles = r.json()\n+        except:\n+            _LOGGER.warning(\"Cannot get the Life360 Circles\")\n+\n+        if self.circles is not None:\n+            #yeah! something in the array\n+            for circle in self.circles['circles']:\n+                #now get all members per circle\n+                url = \"https://api.life360.com/v3/circles/\" + circle['id']\n+                r = requests.get(url, headers=headers)\n+\n+                #check if we have valid response\n+                if r.status_code != 200:\n+                    _LOGGER.error(\"Didn't get a good http response while getting members: %s\", r.status_code)\n+                    return None\n+                    \n+                #trying to parse this\n+                try:\n+                    data = r.json()\n+                    for member in data['members']:\n+                        self.members.append(member)\n+                except:\n+                    _LOGGER.warning(\"Cannot get the Life360 Member\")\n+        \n+        if self.members is None:\n+            _LOGGER.warning(\"Error using Life360 API\")\n+\n+    def _update_info(self, now=None) -> None:\n+        \"\"\"Update the device info.\"\"\"\n+        _LOGGER.debug(\"Updating members %s\", now)\n+        ","path":"homeassistant/components/device_tracker/life360.py","position":123,"original_position":123,"commit_id":"86a366bf643dfdb1d1521cdc1dde667e5c325f40","original_commit_id":"86a366bf643dfdb1d1521cdc1dde667e5c325f40","user":{"login":"houndci-bot","id":6697940,"avatar_url":"https://avatars0.githubusercontent.com/u/6697940?v=4","gravatar_id":"","url":"https://api.github.com/users/houndci-bot","html_url":"https://github.com/houndci-bot","followers_url":"https://api.github.com/users/houndci-bot/followers","following_url":"https://api.github.com/users/houndci-bot/following{/other_user}","gists_url":"https://api.github.com/users/houndci-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci-bot/subscriptions","organizations_url":"https://api.github.com/users/houndci-bot/orgs","repos_url":"https://api.github.com/users/houndci-bot/repos","events_url":"https://api.github.com/users/houndci-bot/events{/privacy}","received_events_url":"https://api.github.com/users/houndci-bot/received_events","type":"User","site_admin":false},"body":"blank line contains whitespace","created_at":"2017-12-01T14:55:04Z","updated_at":"2017-12-01T14:55:05Z","html_url":"https://github.com/home-assistant/home-assistant/pull/10893#discussion_r154363821","pull_request_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/10893","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments/154363821"},"html":{"href":"https://github.com/home-assistant/home-assistant/pull/10893#discussion_r154363821"},"pull_request":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/10893"}}},"pull_request":{"url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/10893","id":155879878,"html_url":"https://github.com/home-assistant/home-assistant/pull/10893","diff_url":"https://github.com/home-assistant/home-assistant/pull/10893.diff","patch_url":"https://github.com/home-assistant/home-assistant/pull/10893.patch","issue_url":"https://api.github.com/repos/home-assistant/home-assistant/issues/10893","number":10893,"state":"open","locked":false,"title":"Added support for Life360","user":{"login":"rmettes","id":34164155,"avatar_url":"https://avatars3.githubusercontent.com/u/34164155?v=4","gravatar_id":"","url":"https://api.github.com/users/rmettes","html_url":"https://github.com/rmettes","followers_url":"https://api.github.com/users/rmettes/followers","following_url":"https://api.github.com/users/rmettes/following{/other_user}","gists_url":"https://api.github.com/users/rmettes/gists{/gist_id}","starred_url":"https://api.github.com/users/rmettes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmettes/subscriptions","organizations_url":"https://api.github.com/users/rmettes/orgs","repos_url":"https://api.github.com/users/rmettes/repos","events_url":"https://api.github.com/users/rmettes/events{/privacy}","received_events_url":"https://api.github.com/users/rmettes/received_events","type":"User","site_admin":false},"body":"## Description:\r\ndevice_tracker for using the Life360 service\r\n\r\n## Example entry for `configuration.yaml` (if applicable):\r\n```yaml\r\ndevice_tracker:\r\n  - platform: life360\r\n    username: [username]\r\n    password: [password]\r\n\r\n```\r\n\r\n## Checklist:\r\n\r\nIf user exposed functionality or configuration variables are added/changed:\r\n  - [ ] Documentation added/updated in [home-assistant.github.io](https://github.com/home-assistant/home-assistant.github.io)\r\n\r\nIf the code communicates with devices, web services, or third-party tools:\r\n  - [ ] Local tests with `tox` run successfully. **Your PR cannot be merged unless tests pass**\r\n  - [ ] New dependencies have been added to the `REQUIREMENTS` variable ([example][ex-requir]).\r\n  - [ ] New dependencies are only imported inside functions that use them ([example][ex-import]).\r\n  - [ ] New dependencies have been added to `requirements_all.txt` by running `script/gen_requirements_all.py`.\r\n  - [ ] New files were added to `.coveragerc`.\r\n\r\nIf the code does not interact with devices:\r\n  - [ ] Local tests with `tox` run successfully. **Your PR cannot be merged unless tests pass**\r\n  - [ ] Tests have been added to verify that the new code works.\r\n\r\n[ex-requir]: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/keyboard.py#L14\r\n[ex-import]: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/keyboard.py#L54\r\n","created_at":"2017-12-01T14:54:57Z","updated_at":"2017-12-01T14:55:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e284e59989271551df68cdd22f6ee8e4eb3f33aa","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/10893/commits","review_comments_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/10893/comments","review_comment_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments{/number}","comments_url":"https://api.github.com/repos/home-assistant/home-assistant/issues/10893/comments","statuses_url":"https://api.github.com/repos/home-assistant/home-assistant/statuses/86a366bf643dfdb1d1521cdc1dde667e5c325f40","head":{"label":"rmettes:device_tracker-Life360","ref":"device_tracker-Life360","sha":"86a366bf643dfdb1d1521cdc1dde667e5c325f40","user":{"login":"rmettes","id":34164155,"avatar_url":"https://avatars3.githubusercontent.com/u/34164155?v=4","gravatar_id":"","url":"https://api.github.com/users/rmettes","html_url":"https://github.com/rmettes","followers_url":"https://api.github.com/users/rmettes/followers","following_url":"https://api.github.com/users/rmettes/following{/other_user}","gists_url":"https://api.github.com/users/rmettes/gists{/gist_id}","starred_url":"https://api.github.com/users/rmettes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmettes/subscriptions","organizations_url":"https://api.github.com/users/rmettes/orgs","repos_url":"https://api.github.com/users/rmettes/repos","events_url":"https://api.github.com/users/rmettes/events{/privacy}","received_events_url":"https://api.github.com/users/rmettes/received_events","type":"User","site_admin":false},"repo":{"id":112749108,"name":"home-assistant","full_name":"rmettes/home-assistant","owner":{"login":"rmettes","id":34164155,"avatar_url":"https://avatars3.githubusercontent.com/u/34164155?v=4","gravatar_id":"","url":"https://api.github.com/users/rmettes","html_url":"https://github.com/rmettes","followers_url":"https://api.github.com/users/rmettes/followers","following_url":"https://api.github.com/users/rmettes/following{/other_user}","gists_url":"https://api.github.com/users/rmettes/gists{/gist_id}","starred_url":"https://api.github.com/users/rmettes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmettes/subscriptions","organizations_url":"https://api.github.com/users/rmettes/orgs","repos_url":"https://api.github.com/users/rmettes/repos","events_url":"https://api.github.com/users/rmettes/events{/privacy}","received_events_url":"https://api.github.com/users/rmettes/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rmettes/home-assistant","description":":house_with_garden: Open-source home automation platform running on Python 3","fork":true,"url":"https://api.github.com/repos/rmettes/home-assistant","forks_url":"https://api.github.com/repos/rmettes/home-assistant/forks","keys_url":"https://api.github.com/repos/rmettes/home-assistant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rmettes/home-assistant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rmettes/home-assistant/teams","hooks_url":"https://api.github.com/repos/rmettes/home-assistant/hooks","issue_events_url":"https://api.github.com/repos/rmettes/home-assistant/issues/events{/number}","events_url":"https://api.github.com/repos/rmettes/home-assistant/events","assignees_url":"https://api.github.com/repos/rmettes/home-assistant/assignees{/user}","branches_url":"https://api.github.com/repos/rmettes/home-assistant/branches{/branch}","tags_url":"https://api.github.com/repos/rmettes/home-assistant/tags","blobs_url":"https://api.github.com/repos/rmettes/home-assistant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rmettes/home-assistant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rmettes/home-assistant/git/refs{/sha}","trees_url":"https://api.github.com/repos/rmettes/home-assistant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rmettes/home-assistant/statuses/{sha}","languages_url":"https://api.github.com/repos/rmettes/home-assistant/languages","stargazers_url":"https://api.github.com/repos/rmettes/home-assistant/stargazers","contributors_url":"https://api.github.com/repos/rmettes/home-assistant/contributors","subscribers_url":"https://api.github.com/repos/rmettes/home-assistant/subscribers","subscription_url":"https://api.github.com/repos/rmettes/home-assistant/subscription","commits_url":"https://api.github.com/repos/rmettes/home-assistant/commits{/sha}","git_commits_url":"https://api.github.com/repos/rmettes/home-assistant/git/commits{/sha}","comments_url":"https://api.github.com/repos/rmettes/home-assistant/comments{/number}","issue_comment_url":"https://api.github.com/repos/rmettes/home-assistant/issues/comments{/number}","contents_url":"https://api.github.com/repos/rmettes/home-assistant/contents/{+path}","compare_url":"https://api.github.com/repos/rmettes/home-assistant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rmettes/home-assistant/merges","archive_url":"https://api.github.com/repos/rmettes/home-assistant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rmettes/home-assistant/downloads","issues_url":"https://api.github.com/repos/rmettes/home-assistant/issues{/number}","pulls_url":"https://api.github.com/repos/rmettes/home-assistant/pulls{/number}","milestones_url":"https://api.github.com/repos/rmettes/home-assistant/milestones{/number}","notifications_url":"https://api.github.com/repos/rmettes/home-assistant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rmettes/home-assistant/labels{/name}","releases_url":"https://api.github.com/repos/rmettes/home-assistant/releases{/id}","deployments_url":"https://api.github.com/repos/rmettes/home-assistant/deployments","created_at":"2017-12-01T14:29:28Z","updated_at":"2017-12-01T14:29:35Z","pushed_at":"2017-12-01T14:47:07Z","git_url":"git://github.com/rmettes/home-assistant.git","ssh_url":"git@github.com:rmettes/home-assistant.git","clone_url":"https://github.com/rmettes/home-assistant.git","svn_url":"https://github.com/rmettes/home-assistant","homepage":"https://home-assistant.io","size":75917,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"home-assistant:dev","ref":"dev","sha":"bc4de4e76978629b8e8aaa49c6c7fb668a28194b","user":{"login":"home-assistant","id":13844975,"avatar_url":"https://avatars3.githubusercontent.com/u/13844975?v=4","gravatar_id":"","url":"https://api.github.com/users/home-assistant","html_url":"https://github.com/home-assistant","followers_url":"https://api.github.com/users/home-assistant/followers","following_url":"https://api.github.com/users/home-assistant/following{/other_user}","gists_url":"https://api.github.com/users/home-assistant/gists{/gist_id}","starred_url":"https://api.github.com/users/home-assistant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/home-assistant/subscriptions","organizations_url":"https://api.github.com/users/home-assistant/orgs","repos_url":"https://api.github.com/users/home-assistant/repos","events_url":"https://api.github.com/users/home-assistant/events{/privacy}","received_events_url":"https://api.github.com/users/home-assistant/received_events","type":"Organization","site_admin":false},"repo":{"id":12888993,"name":"home-assistant","full_name":"home-assistant/home-assistant","owner":{"login":"home-assistant","id":13844975,"avatar_url":"https://avatars3.githubusercontent.com/u/13844975?v=4","gravatar_id":"","url":"https://api.github.com/users/home-assistant","html_url":"https://github.com/home-assistant","followers_url":"https://api.github.com/users/home-assistant/followers","following_url":"https://api.github.com/users/home-assistant/following{/other_user}","gists_url":"https://api.github.com/users/home-assistant/gists{/gist_id}","starred_url":"https://api.github.com/users/home-assistant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/home-assistant/subscriptions","organizations_url":"https://api.github.com/users/home-assistant/orgs","repos_url":"https://api.github.com/users/home-assistant/repos","events_url":"https://api.github.com/users/home-assistant/events{/privacy}","received_events_url":"https://api.github.com/users/home-assistant/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/home-assistant/home-assistant","description":":house_with_garden: Open-source home automation platform running on Python 3","fork":false,"url":"https://api.github.com/repos/home-assistant/home-assistant","forks_url":"https://api.github.com/repos/home-assistant/home-assistant/forks","keys_url":"https://api.github.com/repos/home-assistant/home-assistant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/home-assistant/home-assistant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/home-assistant/home-assistant/teams","hooks_url":"https://api.github.com/repos/home-assistant/home-assistant/hooks","issue_events_url":"https://api.github.com/repos/home-assistant/home-assistant/issues/events{/number}","events_url":"https://api.github.com/repos/home-assistant/home-assistant/events","assignees_url":"https://api.github.com/repos/home-assistant/home-assistant/assignees{/user}","branches_url":"https://api.github.com/repos/home-assistant/home-assistant/branches{/branch}","tags_url":"https://api.github.com/repos/home-assistant/home-assistant/tags","blobs_url":"https://api.github.com/repos/home-assistant/home-assistant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/home-assistant/home-assistant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/home-assistant/home-assistant/git/refs{/sha}","trees_url":"https://api.github.com/repos/home-assistant/home-assistant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/home-assistant/home-assistant/statuses/{sha}","languages_url":"https://api.github.com/repos/home-assistant/home-assistant/languages","stargazers_url":"https://api.github.com/repos/home-assistant/home-assistant/stargazers","contributors_url":"https://api.github.com/repos/home-assistant/home-assistant/contributors","subscribers_url":"https://api.github.com/repos/home-assistant/home-assistant/subscribers","subscription_url":"https://api.github.com/repos/home-assistant/home-assistant/subscription","commits_url":"https://api.github.com/repos/home-assistant/home-assistant/commits{/sha}","git_commits_url":"https://api.github.com/repos/home-assistant/home-assistant/git/commits{/sha}","comments_url":"https://api.github.com/repos/home-assistant/home-assistant/comments{/number}","issue_comment_url":"https://api.github.com/repos/home-assistant/home-assistant/issues/comments{/number}","contents_url":"https://api.github.com/repos/home-assistant/home-assistant/contents/{+path}","compare_url":"https://api.github.com/repos/home-assistant/home-assistant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/home-assistant/home-assistant/merges","archive_url":"https://api.github.com/repos/home-assistant/home-assistant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/home-assistant/home-assistant/downloads","issues_url":"https://api.github.com/repos/home-assistant/home-assistant/issues{/number}","pulls_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls{/number}","milestones_url":"https://api.github.com/repos/home-assistant/home-assistant/milestones{/number}","notifications_url":"https://api.github.com/repos/home-assistant/home-assistant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/home-assistant/home-assistant/labels{/name}","releases_url":"https://api.github.com/repos/home-assistant/home-assistant/releases{/id}","deployments_url":"https://api.github.com/repos/home-assistant/home-assistant/deployments","created_at":"2013-09-17T07:29:48Z","updated_at":"2017-12-01T14:54:28Z","pushed_at":"2017-12-01T14:54:58Z","git_url":"git://github.com/home-assistant/home-assistant.git","ssh_url":"git@github.com:home-assistant/home-assistant.git","clone_url":"https://github.com/home-assistant/home-assistant.git","svn_url":"https://github.com/home-assistant/home-assistant","homepage":"https://home-assistant.io","size":75917,"stargazers_count":10597,"watchers_count":10597,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3011,"mirror_url":null,"archived":false,"open_issues_count":643,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":3011,"open_issues":643,"watchers":10597,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/10893"},"html":{"href":"https://github.com/home-assistant/home-assistant/pull/10893"},"issue":{"href":"https://api.github.com/repos/home-assistant/home-assistant/issues/10893"},"comments":{"href":"https://api.github.com/repos/home-assistant/home-assistant/issues/10893/comments"},"review_comments":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/10893/comments"},"review_comment":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/10893/commits"},"statuses":{"href":"https://api.github.com/repos/home-assistant/home-assistant/statuses/86a366bf643dfdb1d1521cdc1dde667e5c325f40"}},"author_association":"NONE"}}
{"actor":{"display_login":"houndci-bot"}}