{"action":"created","comment":{"url":"https://api.github.com/repos/balloob/home-assistant/pulls/comments/39362856","id":39362856,"diff_hunk":"@@ -0,0 +1,141 @@\n+\"\"\"\n+homeassistant.components.sensor.rest\n+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n+The rest sensor will consume JSON responses sent by an exposed REST API.\n+\n+Configuration:\n+\n+To use the rest sensor you will need to add something like the following\n+to your configuration.yaml file.\n+\n+sensor:\n+  platform: arest\n+    name: REST sensor\n+    resource: http://IP_ADDRESS/ENDPOINT\n+    variable: temperature\n+    unit: '°C'\n+\n+Variables:\n+\n+name\n+*Optional\n+The name of the sensor. Default is 'REST Sensor'.\n+\n+resource\n+*Required\n+The full URL of the REST service/endpoint that provide the JSON response.\n+\n+variable\n+*Required\n+The name of the variable inside the JSON response you want to monitor.\n+\n+unit\n+*Optional\n+Defines the units of measurement of the sensor, if any.\n+\n+For more details about this platform, please refer to the documentation at\n+https://home-assistant.io/components/sensor.rest.html\n+\"\"\"\n+import logging\n+from requests import get, exceptions\n+from datetime import timedelta\n+\n+from homeassistant.util import Throttle\n+from homeassistant.helpers.entity import Entity\n+\n+_LOGGER = logging.getLogger(__name__)\n+\n+DEFAULT_NAME = \"REST Sensor\"\n+\n+# Return cached results if last scan was less then this time ago\n+MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)\n+\n+\n+# pylint: disable=unused-variable\n+def setup_platform(hass, config, add_devices, discovery_info=None):\n+    \"\"\" Get the REST sensor. \"\"\"\n+\n+    resource = config.get('resource', None)\n+\n+    try:\n+        response = get(resource, timeout=10)\n+    except exceptions.MissingSchema:\n+        _LOGGER.error(\"Missing resource or schema in configuration. \"\n+                      \"Add http:// to your URL.\")\n+        return False\n+    except exceptions.ConnectionError:\n+        _LOGGER.error(\"No route to resource/endpoint. \"\n+                      \"Please check the URL in the configuration file.\")\n+        return False\n+\n+    rest = RestData(resource)\n+\n+    dev = []\n+    add_devices([RestSensor(rest,\n+                            config.get('name', DEFAULT_NAME),\n+                            config.get('variable'),\n+                            config.get('unit'))])\n+    add_devices(dev)","path":"homeassistant/components/sensor/rest.py","position":78,"original_position":78,"commit_id":"246184507c206bb8430c3d738e70959bd427af2a","original_commit_id":"246184507c206bb8430c3d738e70959bd427af2a","user":{"login":"fabaff","id":116184,"avatar_url":"https://avatars.githubusercontent.com/u/116184?v=3","gravatar_id":"","url":"https://api.github.com/users/fabaff","html_url":"https://github.com/fabaff","followers_url":"https://api.github.com/users/fabaff/followers","following_url":"https://api.github.com/users/fabaff/following{/other_user}","gists_url":"https://api.github.com/users/fabaff/gists{/gist_id}","starred_url":"https://api.github.com/users/fabaff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabaff/subscriptions","organizations_url":"https://api.github.com/users/fabaff/orgs","repos_url":"https://api.github.com/users/fabaff/repos","events_url":"https://api.github.com/users/fabaff/events{/privacy}","received_events_url":"https://api.github.com/users/fabaff/received_events","type":"User","site_admin":false},"body":"In the current state it is. I was thinking about allowing multiple sensors to be created but changed that, later.\r\n\r\nWill be removed.","created_at":"2015-09-14T05:51:09Z","updated_at":"2015-09-14T05:51:09Z","html_url":"https://github.com/balloob/home-assistant/pull/360#discussion_r39362856","pull_request_url":"https://api.github.com/repos/balloob/home-assistant/pulls/360","_links":{"self":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/comments/39362856"},"html":{"href":"https://github.com/balloob/home-assistant/pull/360#discussion_r39362856"},"pull_request":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/360"}}},"pull_request":{"url":"https://api.github.com/repos/balloob/home-assistant/pulls/360","id":44880471,"html_url":"https://github.com/balloob/home-assistant/pull/360","diff_url":"https://github.com/balloob/home-assistant/pull/360.diff","patch_url":"https://github.com/balloob/home-assistant/pull/360.patch","issue_url":"https://api.github.com/repos/balloob/home-assistant/issues/360","number":360,"state":"open","locked":false,"title":"Rest sensor","user":{"login":"fabaff","id":116184,"avatar_url":"https://avatars.githubusercontent.com/u/116184?v=3","gravatar_id":"","url":"https://api.github.com/users/fabaff","html_url":"https://github.com/fabaff","followers_url":"https://api.github.com/users/fabaff/followers","following_url":"https://api.github.com/users/fabaff/following{/other_user}","gists_url":"https://api.github.com/users/fabaff/gists{/gist_id}","starred_url":"https://api.github.com/users/fabaff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabaff/subscriptions","organizations_url":"https://api.github.com/users/fabaff/orgs","repos_url":"https://api.github.com/users/fabaff/repos","events_url":"https://api.github.com/users/fabaff/events{/privacy}","received_events_url":"https://api.github.com/users/fabaff/received_events","type":"User","site_admin":false},"body":"This is a basic implementation of a REST sensor. ","created_at":"2015-09-13T20:47:21Z","updated_at":"2015-09-14T05:51:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5d43bc5da52f4ae22fb108532b873de56889d3c8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/balloob/home-assistant/pulls/360/commits","review_comments_url":"https://api.github.com/repos/balloob/home-assistant/pulls/360/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/360/comments","statuses_url":"https://api.github.com/repos/balloob/home-assistant/statuses/246184507c206bb8430c3d738e70959bd427af2a","head":{"label":"fabaff:rest-sensor","ref":"rest-sensor","sha":"246184507c206bb8430c3d738e70959bd427af2a","user":{"login":"fabaff","id":116184,"avatar_url":"https://avatars.githubusercontent.com/u/116184?v=3","gravatar_id":"","url":"https://api.github.com/users/fabaff","html_url":"https://github.com/fabaff","followers_url":"https://api.github.com/users/fabaff/followers","following_url":"https://api.github.com/users/fabaff/following{/other_user}","gists_url":"https://api.github.com/users/fabaff/gists{/gist_id}","starred_url":"https://api.github.com/users/fabaff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabaff/subscriptions","organizations_url":"https://api.github.com/users/fabaff/orgs","repos_url":"https://api.github.com/users/fabaff/repos","events_url":"https://api.github.com/users/fabaff/events{/privacy}","received_events_url":"https://api.github.com/users/fabaff/received_events","type":"User","site_admin":false},"repo":{"id":36302973,"name":"home-assistant","full_name":"fabaff/home-assistant","owner":{"login":"fabaff","id":116184,"avatar_url":"https://avatars.githubusercontent.com/u/116184?v=3","gravatar_id":"","url":"https://api.github.com/users/fabaff","html_url":"https://github.com/fabaff","followers_url":"https://api.github.com/users/fabaff/followers","following_url":"https://api.github.com/users/fabaff/following{/other_user}","gists_url":"https://api.github.com/users/fabaff/gists{/gist_id}","starred_url":"https://api.github.com/users/fabaff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabaff/subscriptions","organizations_url":"https://api.github.com/users/fabaff/orgs","repos_url":"https://api.github.com/users/fabaff/repos","events_url":"https://api.github.com/users/fabaff/events{/privacy}","received_events_url":"https://api.github.com/users/fabaff/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fabaff/home-assistant","description":"Open-source home automation platform running on Python 3","fork":true,"url":"https://api.github.com/repos/fabaff/home-assistant","forks_url":"https://api.github.com/repos/fabaff/home-assistant/forks","keys_url":"https://api.github.com/repos/fabaff/home-assistant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fabaff/home-assistant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fabaff/home-assistant/teams","hooks_url":"https://api.github.com/repos/fabaff/home-assistant/hooks","issue_events_url":"https://api.github.com/repos/fabaff/home-assistant/issues/events{/number}","events_url":"https://api.github.com/repos/fabaff/home-assistant/events","assignees_url":"https://api.github.com/repos/fabaff/home-assistant/assignees{/user}","branches_url":"https://api.github.com/repos/fabaff/home-assistant/branches{/branch}","tags_url":"https://api.github.com/repos/fabaff/home-assistant/tags","blobs_url":"https://api.github.com/repos/fabaff/home-assistant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fabaff/home-assistant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fabaff/home-assistant/git/refs{/sha}","trees_url":"https://api.github.com/repos/fabaff/home-assistant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fabaff/home-assistant/statuses/{sha}","languages_url":"https://api.github.com/repos/fabaff/home-assistant/languages","stargazers_url":"https://api.github.com/repos/fabaff/home-assistant/stargazers","contributors_url":"https://api.github.com/repos/fabaff/home-assistant/contributors","subscribers_url":"https://api.github.com/repos/fabaff/home-assistant/subscribers","subscription_url":"https://api.github.com/repos/fabaff/home-assistant/subscription","commits_url":"https://api.github.com/repos/fabaff/home-assistant/commits{/sha}","git_commits_url":"https://api.github.com/repos/fabaff/home-assistant/git/commits{/sha}","comments_url":"https://api.github.com/repos/fabaff/home-assistant/comments{/number}","issue_comment_url":"https://api.github.com/repos/fabaff/home-assistant/issues/comments{/number}","contents_url":"https://api.github.com/repos/fabaff/home-assistant/contents/{+path}","compare_url":"https://api.github.com/repos/fabaff/home-assistant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fabaff/home-assistant/merges","archive_url":"https://api.github.com/repos/fabaff/home-assistant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fabaff/home-assistant/downloads","issues_url":"https://api.github.com/repos/fabaff/home-assistant/issues{/number}","pulls_url":"https://api.github.com/repos/fabaff/home-assistant/pulls{/number}","milestones_url":"https://api.github.com/repos/fabaff/home-assistant/milestones{/number}","notifications_url":"https://api.github.com/repos/fabaff/home-assistant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fabaff/home-assistant/labels{/name}","releases_url":"https://api.github.com/repos/fabaff/home-assistant/releases{/id}","created_at":"2015-05-26T14:52:30Z","updated_at":"2015-09-01T11:31:26Z","pushed_at":"2015-09-13T20:42:23Z","git_url":"git://github.com/fabaff/home-assistant.git","ssh_url":"git@github.com:fabaff/home-assistant.git","clone_url":"https://github.com/fabaff/home-assistant.git","svn_url":"https://github.com/fabaff/home-assistant","homepage":"https://home-assistant.io","size":18752,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"balloob:dev","ref":"dev","sha":"40aa661340c0d30529eb736e38ca4b3bcf8929a7","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}","created_at":"2013-09-17T07:29:48Z","updated_at":"2015-09-13T21:10:16Z","pushed_at":"2015-09-14T05:31:57Z","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":26283,"stargazers_count":2060,"watchers_count":2060,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":242,"mirror_url":null,"open_issues_count":35,"forks":242,"open_issues":35,"watchers":2060,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/360"},"html":{"href":"https://github.com/balloob/home-assistant/pull/360"},"issue":{"href":"https://api.github.com/repos/balloob/home-assistant/issues/360"},"comments":{"href":"https://api.github.com/repos/balloob/home-assistant/issues/360/comments"},"review_comments":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/360/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/360/commits"},"statuses":{"href":"https://api.github.com/repos/balloob/home-assistant/statuses/246184507c206bb8430c3d738e70959bd427af2a"}}}}