{"action":"created","comment":{"url":"https://api.github.com/repos/balloob/home-assistant/pulls/comments/45696837","id":45696837,"diff_hunk":"@@ -68,6 +70,69 @@ def is_on(self):\n         \"\"\" True if device is on. \"\"\"\n         return self._state\n \n+\n+class ArestSwitchFunction(ArestSwitchBase):\n+    \"\"\" Implements an aREST switch. Based on functions. \"\"\"\n+\n+    def __init__(self, resource, location, name, func):\n+        super().__init__(resource, location, name)\n+        self._func = func\n+\n+        request = requests.get('{}/{}'.format(self._resource, self._func),\n+                               timeout=10)\n+\n+        if request.status_code is not 200:\n+            _LOGGER.error(\"Can't find function. Is device offline?\")\n+            return\n+\n+        try:\n+            request.json()['return_value']\n+        except KeyError:\n+            _LOGGER.error(\"Function doesn't include return value. Is the function name correct.\")\n+        except ValueError:\n+            _LOGGER.error(\"Function response invalid. Is the function name correct.\")\n+\n+    def turn_on(self, **kwargs):\n+        \"\"\" Turn the device on. \"\"\"\n+        request = requests.get('{}/{}'.format(self._resource, self._func),\n+                               timeout=10, params={\"params\": \"1\"})\n+\n+        if request.status_code == 200:\n+            self._state = True\n+        else:\n+            _LOGGER.error(\"Can't turn on function %s at %s. Is device offline?\",\n+                          self._func, self._resource)\n+\n+    def turn_off(self, **kwargs):\n+        \"\"\" Turn the device off. \"\"\"\n+        request = requests.get('{}/{}'.format(self._resource, self._func),\n+                               timeout=10, params={\"params\": \"0\"})\n+\n+        if request.status_code == 200:\n+            self._state = False\n+        else:\n+            _LOGGER.error(\"Can't turn off function %s at %s. Is device offline?\",\n+                          self._func, self._resource)\n+\n+    def update(self):","path":"homeassistant/components/switch/arest.py","position":94,"original_position":94,"commit_id":"4206330f5e3db5cd2af9659e1fa4c236338b12b1","original_commit_id":"4206330f5e3db5cd2af9659e1fa4c236338b12b1","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":"It looks like this one is similar to the pin based one. Can you set the url in the constructor and move this method to the base class?\r\n\r\nIf you define `turn_on_params` and `turn_off_params` in the constructor too, you'll be able to re-use `turn_on` and `turn_off` too.","created_at":"2015-11-24T04:49:37Z","updated_at":"2015-11-24T04:49:37Z","html_url":"https://github.com/balloob/home-assistant/pull/652#discussion_r45696837","pull_request_url":"https://api.github.com/repos/balloob/home-assistant/pulls/652","_links":{"self":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/comments/45696837"},"html":{"href":"https://github.com/balloob/home-assistant/pull/652#discussion_r45696837"},"pull_request":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/652"}}},"pull_request":{"url":"https://api.github.com/repos/balloob/home-assistant/pulls/652","id":51475858,"html_url":"https://github.com/balloob/home-assistant/pull/652","diff_url":"https://github.com/balloob/home-assistant/pull/652.diff","patch_url":"https://github.com/balloob/home-assistant/pull/652.patch","issue_url":"https://api.github.com/repos/balloob/home-assistant/issues/652","number":652,"state":"open","locked":false,"title":"function support for aREST backend","user":{"login":"bachp","id":333807,"avatar_url":"https://avatars.githubusercontent.com/u/333807?v=3","gravatar_id":"","url":"https://api.github.com/users/bachp","html_url":"https://github.com/bachp","followers_url":"https://api.github.com/users/bachp/followers","following_url":"https://api.github.com/users/bachp/following{/other_user}","gists_url":"https://api.github.com/users/bachp/gists{/gist_id}","starred_url":"https://api.github.com/users/bachp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bachp/subscriptions","organizations_url":"https://api.github.com/users/bachp/orgs","repos_url":"https://api.github.com/users/bachp/repos","events_url":"https://api.github.com/users/bachp/events{/privacy}","received_events_url":"https://api.github.com/users/bachp/received_events","type":"User","site_admin":false},"body":"The implementation sends /<name>?params=1 for turn_on and /<name>?params=0 for turn_off\r\nIt uses the return value of the function to determine the current state.\r\n0=Off, 1=On","created_at":"2015-11-22T21:53:42Z","updated_at":"2015-11-24T04:49:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5aec25c938cb92fb54aeb78d4f6184a2ea0e5fd6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/balloob/home-assistant/pulls/652/commits","review_comments_url":"https://api.github.com/repos/balloob/home-assistant/pulls/652/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/652/comments","statuses_url":"https://api.github.com/repos/balloob/home-assistant/statuses/4206330f5e3db5cd2af9659e1fa4c236338b12b1","head":{"label":"bachp:arest-function","ref":"arest-function","sha":"4206330f5e3db5cd2af9659e1fa4c236338b12b1","user":{"login":"bachp","id":333807,"avatar_url":"https://avatars.githubusercontent.com/u/333807?v=3","gravatar_id":"","url":"https://api.github.com/users/bachp","html_url":"https://github.com/bachp","followers_url":"https://api.github.com/users/bachp/followers","following_url":"https://api.github.com/users/bachp/following{/other_user}","gists_url":"https://api.github.com/users/bachp/gists{/gist_id}","starred_url":"https://api.github.com/users/bachp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bachp/subscriptions","organizations_url":"https://api.github.com/users/bachp/orgs","repos_url":"https://api.github.com/users/bachp/repos","events_url":"https://api.github.com/users/bachp/events{/privacy}","received_events_url":"https://api.github.com/users/bachp/received_events","type":"User","site_admin":false},"repo":{"id":44557101,"name":"home-assistant","full_name":"bachp/home-assistant","owner":{"login":"bachp","id":333807,"avatar_url":"https://avatars.githubusercontent.com/u/333807?v=3","gravatar_id":"","url":"https://api.github.com/users/bachp","html_url":"https://github.com/bachp","followers_url":"https://api.github.com/users/bachp/followers","following_url":"https://api.github.com/users/bachp/following{/other_user}","gists_url":"https://api.github.com/users/bachp/gists{/gist_id}","starred_url":"https://api.github.com/users/bachp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bachp/subscriptions","organizations_url":"https://api.github.com/users/bachp/orgs","repos_url":"https://api.github.com/users/bachp/repos","events_url":"https://api.github.com/users/bachp/events{/privacy}","received_events_url":"https://api.github.com/users/bachp/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bachp/home-assistant","description":"Open-source home automation platform running on Python 3","fork":true,"url":"https://api.github.com/repos/bachp/home-assistant","forks_url":"https://api.github.com/repos/bachp/home-assistant/forks","keys_url":"https://api.github.com/repos/bachp/home-assistant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bachp/home-assistant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bachp/home-assistant/teams","hooks_url":"https://api.github.com/repos/bachp/home-assistant/hooks","issue_events_url":"https://api.github.com/repos/bachp/home-assistant/issues/events{/number}","events_url":"https://api.github.com/repos/bachp/home-assistant/events","assignees_url":"https://api.github.com/repos/bachp/home-assistant/assignees{/user}","branches_url":"https://api.github.com/repos/bachp/home-assistant/branches{/branch}","tags_url":"https://api.github.com/repos/bachp/home-assistant/tags","blobs_url":"https://api.github.com/repos/bachp/home-assistant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bachp/home-assistant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bachp/home-assistant/git/refs{/sha}","trees_url":"https://api.github.com/repos/bachp/home-assistant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bachp/home-assistant/statuses/{sha}","languages_url":"https://api.github.com/repos/bachp/home-assistant/languages","stargazers_url":"https://api.github.com/repos/bachp/home-assistant/stargazers","contributors_url":"https://api.github.com/repos/bachp/home-assistant/contributors","subscribers_url":"https://api.github.com/repos/bachp/home-assistant/subscribers","subscription_url":"https://api.github.com/repos/bachp/home-assistant/subscription","commits_url":"https://api.github.com/repos/bachp/home-assistant/commits{/sha}","git_commits_url":"https://api.github.com/repos/bachp/home-assistant/git/commits{/sha}","comments_url":"https://api.github.com/repos/bachp/home-assistant/comments{/number}","issue_comment_url":"https://api.github.com/repos/bachp/home-assistant/issues/comments{/number}","contents_url":"https://api.github.com/repos/bachp/home-assistant/contents/{+path}","compare_url":"https://api.github.com/repos/bachp/home-assistant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bachp/home-assistant/merges","archive_url":"https://api.github.com/repos/bachp/home-assistant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bachp/home-assistant/downloads","issues_url":"https://api.github.com/repos/bachp/home-assistant/issues{/number}","pulls_url":"https://api.github.com/repos/bachp/home-assistant/pulls{/number}","milestones_url":"https://api.github.com/repos/bachp/home-assistant/milestones{/number}","notifications_url":"https://api.github.com/repos/bachp/home-assistant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bachp/home-assistant/labels{/name}","releases_url":"https://api.github.com/repos/bachp/home-assistant/releases{/id}","created_at":"2015-10-19T19:04:09Z","updated_at":"2015-10-19T19:04:12Z","pushed_at":"2015-11-23T20:47:35Z","git_url":"git://github.com/bachp/home-assistant.git","ssh_url":"git@github.com:bachp/home-assistant.git","clone_url":"https://github.com/bachp/home-assistant.git","svn_url":"https://github.com/bachp/home-assistant","homepage":"https://home-assistant.io","size":25401,"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":"dev"}},"base":{"label":"balloob:dev","ref":"dev","sha":"7acb3dffe40f3ae9c4c2bf9aaa470acf007142a3","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-11-24T00:59:57Z","pushed_at":"2015-11-24T04:42:32Z","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":27708,"stargazers_count":2336,"watchers_count":2336,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":311,"mirror_url":null,"open_issues_count":78,"forks":311,"open_issues":78,"watchers":2336,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/652"},"html":{"href":"https://github.com/balloob/home-assistant/pull/652"},"issue":{"href":"https://api.github.com/repos/balloob/home-assistant/issues/652"},"comments":{"href":"https://api.github.com/repos/balloob/home-assistant/issues/652/comments"},"review_comments":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/652/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/652/commits"},"statuses":{"href":"https://api.github.com/repos/balloob/home-assistant/statuses/4206330f5e3db5cd2af9659e1fa4c236338b12b1"}}}}