{"action":"created","comment":{"url":"https://api.github.com/repos/balloob/home-assistant/pulls/comments/50639082","id":50639082,"diff_hunk":"@@ -60,47 +69,119 @@ def owntracks_event_update(topic, payload, qos):\n             data = json.loads(payload)\n         except ValueError:\n             # If invalid JSON\n-            logging.getLogger(__name__).error(\n+            _LOGGER.error(\n                 'Unable to parse payload as JSON: %s', payload)\n             return\n \n         if not isinstance(data, dict) or data.get('_type') != 'transition':\n             return\n \n-        # check if in \"home\" fence or other zone\n-        location = ''\n+        if data['desc'].lower() == 'home':\n+            location = STATE_HOME\n+        else:\n+            location = data['desc']\n+\n+        dev_id, kwargs = _parse_see_args(topic, data)\n+\n         if data['event'] == 'enter':\n+            zone = hass.states.get(\"zone.{}\".format(location))\n+            with LOCK:\n+                if zone is not None:\n+                    kwargs['location_name'] = location\n+                    _enter_region(dev_id, location)\n+                    _LOGGER.info(\"Enter region %s\", location)\n+                    _get_gps_from_zone(kwargs, zone)\n \n-            if data['desc'].lower() == 'home':\n-                location = STATE_HOME\n-            else:\n-                location = data['desc']\n+                see(**kwargs)\n \n         elif data['event'] == 'leave':\n-            location = STATE_NOT_HOME\n+            current_location = hass.states.get(\n+                \"device_tracker.{}\".format(dev_id)).state\n+            new_region = _exit_region(dev_id, location)\n+\n+            if not new_region:\n+                _LOGGER.info(\"Exit from %s to GPS\", location)\n+                see(**kwargs)\n+                _force_state_change_if_needed(dev_id, location, kwargs)","path":"homeassistant/components/device_tracker/owntracks.py","position":110,"original_position":110,"commit_id":"c0d4716301383a25cd57b67d27987d88b2cfb966","original_commit_id":"c0d4716301383a25cd57b67d27987d88b2cfb966","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":"Inline too.","created_at":"2016-01-24T17:57:09Z","updated_at":"2016-01-24T17:57:09Z","html_url":"https://github.com/balloob/home-assistant/pull/976#discussion_r50639082","pull_request_url":"https://api.github.com/repos/balloob/home-assistant/pulls/976","_links":{"self":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/comments/50639082"},"html":{"href":"https://github.com/balloob/home-assistant/pull/976#discussion_r50639082"},"pull_request":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/976"}}},"pull_request":{"url":"https://api.github.com/repos/balloob/home-assistant/pulls/976","id":56984712,"html_url":"https://github.com/balloob/home-assistant/pull/976","diff_url":"https://github.com/balloob/home-assistant/pull/976.diff","patch_url":"https://github.com/balloob/home-assistant/pull/976.patch","issue_url":"https://api.github.com/repos/balloob/home-assistant/issues/976","number":976,"state":"open","locked":false,"title":"Revise OwnTracks region handling, support iBeacons.","user":{"login":"pavoni","id":4487313,"avatar_url":"https://avatars.githubusercontent.com/u/4487313?v=3","gravatar_id":"","url":"https://api.github.com/users/pavoni","html_url":"https://github.com/pavoni","followers_url":"https://api.github.com/users/pavoni/followers","following_url":"https://api.github.com/users/pavoni/following{/other_user}","gists_url":"https://api.github.com/users/pavoni/gists{/gist_id}","starred_url":"https://api.github.com/users/pavoni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pavoni/subscriptions","organizations_url":"https://api.github.com/users/pavoni/orgs","repos_url":"https://api.github.com/users/pavoni/repos","events_url":"https://api.github.com/users/pavoni/events{/privacy}","received_events_url":"https://api.github.com/users/pavoni/received_events","type":"User","site_admin":false},"body":"This PR re-works OwnTracks entry / leave event handling.\r\n\r\nThe previous approach needed to be enabled with `use_events` which then disabled normal location tracking. \r\n\r\nThis takes another approach allowing both` Location events` and `Region events` to be used together. It does this by storing a state to indicate a device is in a region - and using this to temporarily disable `Location` events until you exit the region.\r\n\r\nThere is also revised logic on exiting a region to attempt to update the location based on gps location, and only setting state to `Away` if this didn't already change the current location. This works well with iBeacons inside a larger Home area.\r\n\r\nThere is a small change to allow regions of size '0' not to be picked as priority by location code. This means you can have 'beacon only' zones, which still have a defined location.\r\n\r\n~~The odd thing about the code is using a special state. Open to re-work this another way! I have in mind this could be extended to allow more stanes to support more iBeacon functions (eg are you close to your keys).~~ Revised to use a dictionary (thanks @balloob ).\r\n\r\nThere is a lot of change here - so would be grateful for some feedback - and happy to re-work.","created_at":"2016-01-23T19:49:34Z","updated_at":"2016-01-24T17:57:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c86a280c24bd8e753bb93e337f2921e41bd300e9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/balloob/home-assistant/pulls/976/commits","review_comments_url":"https://api.github.com/repos/balloob/home-assistant/pulls/976/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/976/comments","statuses_url":"https://api.github.com/repos/balloob/home-assistant/statuses/c0d4716301383a25cd57b67d27987d88b2cfb966","head":{"label":"balloob:owntracks_beacon","ref":"owntracks_beacon","sha":"c0d4716301383a25cd57b67d27987d88b2cfb966","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":"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-01-24T03:28:08Z","pushed_at":"2016-01-24T17:46:24Z","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":38374,"stargazers_count":2622,"watchers_count":2622,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":397,"mirror_url":null,"open_issues_count":130,"forks":397,"open_issues":130,"watchers":2622,"default_branch":"dev"}},"base":{"label":"balloob:dev","ref":"dev","sha":"0042e7725da741418fc04479dcc6260c3502c658","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":"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-01-24T03:28:08Z","pushed_at":"2016-01-24T17:46:24Z","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":38374,"stargazers_count":2622,"watchers_count":2622,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":397,"mirror_url":null,"open_issues_count":130,"forks":397,"open_issues":130,"watchers":2622,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/976"},"html":{"href":"https://github.com/balloob/home-assistant/pull/976"},"issue":{"href":"https://api.github.com/repos/balloob/home-assistant/issues/976"},"comments":{"href":"https://api.github.com/repos/balloob/home-assistant/issues/976/comments"},"review_comments":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/976/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/976/commits"},"statuses":{"href":"https://api.github.com/repos/balloob/home-assistant/statuses/c0d4716301383a25cd57b67d27987d88b2cfb966"}}}}