{"action":"created","comment":{"url":"https://api.github.com/repos/balloob/home-assistant/pulls/comments/37162651","id":37162651,"diff_hunk":"@@ -185,3 +203,99 @@ def update(self):\n             self.current_value = 'Tripped' if tripped == '1' else 'Not Tripped'\n         else:\n             self.current_value = 'Unknown'\n+\n+\n+class VeraControllerSensor(VeraControllerDevice):\n+    \"\"\" Represents a Vera Sensor that is discovered by a controller entity. \"\"\"\n+    def __init__(self, hass, config, device_data, discovery_info=None):\n+        super().__init__(hass, config, device_data)\n+        if discovery_info is None:\n+            discovery_info = {}\n+        self._state_variable = self._config.get(\n+            'state_variable',\n+            self.select_state_variable())\n+        self._unit_of_measurement = self._config.get(\n+            'unit_of_measurement',\n+            self.select_units())\n+        self._vera_device_id = self._config.get(\n+            'vera_id',\n+            self._device_data.get('id'))\n+        self._parent_entity_id = discovery_info.get('parent_entity_id', None)\n+\n+    def select_state_variable(self):\n+        \"\"\" Selects the variable to be used for the state of the parent device.\n+        A child sensor that monitors this variable will not be created. \"\"\"\n+        # If no state variable is configured choose one.\n+        # Put the variables in order of preference.\n+        watchable_variables = [\n+            'temperature',\n+            'light',\n+            'tripped',\n+            'batterylevel',\n+            'light',\n+            'armed',\n+            'humidity',\n+            'armedtripped']\n+\n+        for val in watchable_variables:\n+            if val in self._device_data.keys():","path":"homeassistant/components/sensor/vera.py","position":79,"original_position":79,"commit_id":"0e1bba1e67ca85a9e358a5eb8fb0c7e94a145d04","original_commit_id":"0e1bba1e67ca85a9e358a5eb8fb0c7e94a145d04","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":"You can omit the call to `keys()`\r\n```python\r\nif val in self._device_data:\r\n```","created_at":"2015-08-17T07:08:28Z","updated_at":"2015-08-17T07:08:28Z","html_url":"https://github.com/balloob/home-assistant/pull/259#discussion_r37162651","pull_request_url":"https://api.github.com/repos/balloob/home-assistant/pulls/259","_links":{"self":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/comments/37162651"},"html":{"href":"https://github.com/balloob/home-assistant/pull/259#discussion_r37162651"},"pull_request":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/259"}}},"pull_request":{"url":"https://api.github.com/repos/balloob/home-assistant/pulls/259","id":42522317,"html_url":"https://github.com/balloob/home-assistant/pull/259","diff_url":"https://github.com/balloob/home-assistant/pull/259.diff","patch_url":"https://github.com/balloob/home-assistant/pull/259.patch","issue_url":"https://api.github.com/repos/balloob/home-assistant/issues/259","number":259,"state":"open","locked":false,"title":"Big refactor of the Vera integration including new child components","user":{"login":"jamespcole","id":3460982,"avatar_url":"https://avatars.githubusercontent.com/u/3460982?v=3","gravatar_id":"","url":"https://api.github.com/users/jamespcole","html_url":"https://github.com/jamespcole","followers_url":"https://api.github.com/users/jamespcole/followers","following_url":"https://api.github.com/users/jamespcole/following{/other_user}","gists_url":"https://api.github.com/users/jamespcole/gists{/gist_id}","starred_url":"https://api.github.com/users/jamespcole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamespcole/subscriptions","organizations_url":"https://api.github.com/users/jamespcole/orgs","repos_url":"https://api.github.com/users/jamespcole/repos","events_url":"https://api.github.com/users/jamespcole/events{/privacy}","received_events_url":"https://api.github.com/users/jamespcole/received_events","type":"User","site_admin":false},"body":"This is a big rewrite of the Vera integration as well as adding in support for creation of generic child switches, lights and sensors.  There is probably still some work to do(I need some config validation on the child components for example) but I realised the change was actually getting quite large so I thought I would make the pull request so I can start getting feedback before I go too far down the rabbit hole.  I've added documentation to the new files so hopefully it will give you enough info to get an idea of what I'm shooting for.\r\n\r\nAs some background the main issue I was trying to solve is the case of single devices that may have multiple functions or variables.  I wanted the ability for things like my Z-wave door and motion sensors which actually have several functions such as arm/disarm and various properties like, tripped, armed status etc. to be able to easily and automatically spawn multiple child devices based on these functions and properties.  Another issue I have tackling with this update is making fewer HTTP requests to the Vera.  I have recently switched all the lights in my house to Z-wave control as well as the smoke detectors and a bunch more sensors.  In the existing implementation each entity was making requests to the Vera API to query its state and with the large increase in the number of devices this was generating a lot of requests.  The controller component I created allows for a single point of interaction with the Vera and makes a single API request per polling period rather than 1 per device.\r\n\r\nThe update includes the following:\r\n\r\n* A new controller component type that represents a device such as Vera, NinjaBlock etc. that may control many other devices\r\n* Creation of Vera sensors, lights and switches using the discovery mechanism\r\n* New child_switch, child_light and child_sensor entities\r\n* Automatic discovery and creation of child entities for Vera devices that may have multiple functions, eg. sensors with the ability to toggle armed state and simultaneously monitors multiple variable such as temp, humidity, light level\r\n* Support for dimmable Vera lights\r\n\r\nNote: I did make new switch, light and sensor types for this new Vera implementation in the same file as the existing ones.  Once this bit of dev is complete I will deprecate the old implementation and then remove the old code after a grace period.\r\n","created_at":"2015-08-15T17:05:08Z","updated_at":"2015-08-17T07:08:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"06c15e7a94a597dac45cfa5135d48dfe95bb1c5f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/balloob/home-assistant/pulls/259/commits","review_comments_url":"https://api.github.com/repos/balloob/home-assistant/pulls/259/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/259/comments","statuses_url":"https://api.github.com/repos/balloob/home-assistant/statuses/0e1bba1e67ca85a9e358a5eb8fb0c7e94a145d04","head":{"label":"jamespcole:controller-dev2","ref":"controller-dev2","sha":"0e1bba1e67ca85a9e358a5eb8fb0c7e94a145d04","user":{"login":"jamespcole","id":3460982,"avatar_url":"https://avatars.githubusercontent.com/u/3460982?v=3","gravatar_id":"","url":"https://api.github.com/users/jamespcole","html_url":"https://github.com/jamespcole","followers_url":"https://api.github.com/users/jamespcole/followers","following_url":"https://api.github.com/users/jamespcole/following{/other_user}","gists_url":"https://api.github.com/users/jamespcole/gists{/gist_id}","starred_url":"https://api.github.com/users/jamespcole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamespcole/subscriptions","organizations_url":"https://api.github.com/users/jamespcole/orgs","repos_url":"https://api.github.com/users/jamespcole/repos","events_url":"https://api.github.com/users/jamespcole/events{/privacy}","received_events_url":"https://api.github.com/users/jamespcole/received_events","type":"User","site_admin":false},"repo":{"id":31496915,"name":"home-assistant","full_name":"jamespcole/home-assistant","owner":{"login":"jamespcole","id":3460982,"avatar_url":"https://avatars.githubusercontent.com/u/3460982?v=3","gravatar_id":"","url":"https://api.github.com/users/jamespcole","html_url":"https://github.com/jamespcole","followers_url":"https://api.github.com/users/jamespcole/followers","following_url":"https://api.github.com/users/jamespcole/following{/other_user}","gists_url":"https://api.github.com/users/jamespcole/gists{/gist_id}","starred_url":"https://api.github.com/users/jamespcole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamespcole/subscriptions","organizations_url":"https://api.github.com/users/jamespcole/orgs","repos_url":"https://api.github.com/users/jamespcole/repos","events_url":"https://api.github.com/users/jamespcole/events{/privacy}","received_events_url":"https://api.github.com/users/jamespcole/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jamespcole/home-assistant","description":"Open-source home automation platform running on Python 3","fork":true,"url":"https://api.github.com/repos/jamespcole/home-assistant","forks_url":"https://api.github.com/repos/jamespcole/home-assistant/forks","keys_url":"https://api.github.com/repos/jamespcole/home-assistant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jamespcole/home-assistant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jamespcole/home-assistant/teams","hooks_url":"https://api.github.com/repos/jamespcole/home-assistant/hooks","issue_events_url":"https://api.github.com/repos/jamespcole/home-assistant/issues/events{/number}","events_url":"https://api.github.com/repos/jamespcole/home-assistant/events","assignees_url":"https://api.github.com/repos/jamespcole/home-assistant/assignees{/user}","branches_url":"https://api.github.com/repos/jamespcole/home-assistant/branches{/branch}","tags_url":"https://api.github.com/repos/jamespcole/home-assistant/tags","blobs_url":"https://api.github.com/repos/jamespcole/home-assistant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jamespcole/home-assistant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jamespcole/home-assistant/git/refs{/sha}","trees_url":"https://api.github.com/repos/jamespcole/home-assistant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jamespcole/home-assistant/statuses/{sha}","languages_url":"https://api.github.com/repos/jamespcole/home-assistant/languages","stargazers_url":"https://api.github.com/repos/jamespcole/home-assistant/stargazers","contributors_url":"https://api.github.com/repos/jamespcole/home-assistant/contributors","subscribers_url":"https://api.github.com/repos/jamespcole/home-assistant/subscribers","subscription_url":"https://api.github.com/repos/jamespcole/home-assistant/subscription","commits_url":"https://api.github.com/repos/jamespcole/home-assistant/commits{/sha}","git_commits_url":"https://api.github.com/repos/jamespcole/home-assistant/git/commits{/sha}","comments_url":"https://api.github.com/repos/jamespcole/home-assistant/comments{/number}","issue_comment_url":"https://api.github.com/repos/jamespcole/home-assistant/issues/comments{/number}","contents_url":"https://api.github.com/repos/jamespcole/home-assistant/contents/{+path}","compare_url":"https://api.github.com/repos/jamespcole/home-assistant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jamespcole/home-assistant/merges","archive_url":"https://api.github.com/repos/jamespcole/home-assistant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jamespcole/home-assistant/downloads","issues_url":"https://api.github.com/repos/jamespcole/home-assistant/issues{/number}","pulls_url":"https://api.github.com/repos/jamespcole/home-assistant/pulls{/number}","milestones_url":"https://api.github.com/repos/jamespcole/home-assistant/milestones{/number}","notifications_url":"https://api.github.com/repos/jamespcole/home-assistant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jamespcole/home-assistant/labels{/name}","releases_url":"https://api.github.com/repos/jamespcole/home-assistant/releases{/id}","created_at":"2015-03-01T13:12:53Z","updated_at":"2015-03-08T16:44:18Z","pushed_at":"2015-08-16T09:16:21Z","git_url":"git://github.com/jamespcole/home-assistant.git","ssh_url":"git@github.com:jamespcole/home-assistant.git","clone_url":"https://github.com/jamespcole/home-assistant.git","svn_url":"https://github.com/jamespcole/home-assistant","homepage":"https://home-assistant.io","size":15568,"stargazers_count":0,"watchers_count":0,"language":"HTML","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":"d0fc91d84acae136fbb721314479863f2317023f","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-08-17T05:52:00Z","pushed_at":"2015-08-17T05:14:41Z","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":22767,"stargazers_count":1997,"watchers_count":1997,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":212,"mirror_url":null,"open_issues_count":27,"forks":212,"open_issues":27,"watchers":1997,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/259"},"html":{"href":"https://github.com/balloob/home-assistant/pull/259"},"issue":{"href":"https://api.github.com/repos/balloob/home-assistant/issues/259"},"comments":{"href":"https://api.github.com/repos/balloob/home-assistant/issues/259/comments"},"review_comments":{"href":"https://api.github.com/repos/balloob/home-assistant/pulls/259/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/259/commits"},"statuses":{"href":"https://api.github.com/repos/balloob/home-assistant/statuses/0e1bba1e67ca85a9e358a5eb8fb0c7e94a145d04"}}}}