{"action":"created","comment":{"url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments/243702343","pull_request_review_id":187551592,"id":243702343,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0MzcwMjM0Mw==","diff_hunk":"@@ -145,6 +147,71 @@ def attribute_updated(self, attribute, value):\n         self._state = result.get(self.value_attribute, self._state)\n \n \n+class GenericBatterySensor(Sensor):\n+    \"\"\"ZHA generic battery sensor.\"\"\"\n+\n+    report_attribute = 32\n+    value_attribute = 33\n+    battery_sizes = {\n+        0: 'No battery',\n+        1: 'Built in',\n+        2: 'Other',\n+        3: 'AA',\n+        4: 'AAA',\n+        5: 'C',\n+        6: 'D',\n+        7: 'CR2',\n+        8: 'CR123A',\n+        9: 'CR2450',\n+        10: 'CR2032',\n+        11: 'CR1632',\n+        255: 'Unknown'\n+    }\n+\n+    @property\n+    def unit_of_measurement(self):\n+        \"\"\"Return the unit of measurement of this entity.\"\"\"\n+        return '%'\n+\n+    @property\n+    def zcl_reporting_config(self) -> dict:\n+        \"\"\"Return a dict of attribute reporting configuration.\"\"\"\n+        return {\n+            self.cluster: {\n+                self.value_attribute: self.report_config,\n+                self.report_attribute: self.report_config\n+            }\n+        }\n+\n+    async def async_update(self):\n+        \"\"\"Retrieve latest state.\"\"\"\n+        _LOGGER.debug(\"%s async_update\", self.entity_id)\n+\n+        result = await helpers.safe_read(\n+            self._endpoint.power,\n+            [\n+                'battery_size',\n+                'battery_quantity',\n+                'battery_percentage_remaining'\n+            ],\n+            allow_cache=False,\n+            only_cache=(not self._initialized)\n+        )\n+        self._device_state_attributes['battery_size'] = self.battery_sizes.get(\n+            result.get('battery_size', 255), 'Unknown')\n+        self._device_state_attributes['battery_quantity'] = result.get(\n+            'battery_quantity', 'Unknown')\n+        self._state = result.get('battery_percentage_remaining', self._state)\n+\n+    @property\n+    def state(self):\n+        \"\"\"Return the state of the entity.\"\"\"\n+        if self._state == 'unknown' or self._state is None:","path":"homeassistant/components/sensor/zha.py","position":86,"original_position":86,"commit_id":"0fe3a56b210f5b4625aa5529e363fc3f071656b5","original_commit_id":"0fe3a56b210f5b4625aa5529e363fc3f071656b5","user":{"login":"Adminiuga","id":5826160,"node_id":"MDQ6VXNlcjU4MjYxNjA=","avatar_url":"https://avatars1.githubusercontent.com/u/5826160?v=4","gravatar_id":"","url":"https://api.github.com/users/Adminiuga","html_url":"https://github.com/Adminiuga","followers_url":"https://api.github.com/users/Adminiuga/followers","following_url":"https://api.github.com/users/Adminiuga/following{/other_user}","gists_url":"https://api.github.com/users/Adminiuga/gists{/gist_id}","starred_url":"https://api.github.com/users/Adminiuga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Adminiuga/subscriptions","organizations_url":"https://api.github.com/users/Adminiuga/orgs","repos_url":"https://api.github.com/users/Adminiuga/repos","events_url":"https://api.github.com/users/Adminiuga/events{/privacy}","received_events_url":"https://api.github.com/users/Adminiuga/received_events","type":"User","site_admin":false},"body":"For unknown state we should return None","created_at":"2018-12-21T22:06:22Z","updated_at":"2018-12-21T22:06:22Z","html_url":"https://github.com/home-assistant/home-assistant/pull/19363#discussion_r243702343","pull_request_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/19363","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments/243702343"},"html":{"href":"https://github.com/home-assistant/home-assistant/pull/19363#discussion_r243702343"},"pull_request":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/19363"}}},"pull_request":{"url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/19363","id":239003629,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM5MDAzNjI5","html_url":"https://github.com/home-assistant/home-assistant/pull/19363","diff_url":"https://github.com/home-assistant/home-assistant/pull/19363.diff","patch_url":"https://github.com/home-assistant/home-assistant/pull/19363.patch","issue_url":"https://api.github.com/repos/home-assistant/home-assistant/issues/19363","number":19363,"state":"open","locked":false,"title":"Add ZHA battery sensor","user":{"login":"dmulcahey","id":1335687,"node_id":"MDQ6VXNlcjEzMzU2ODc=","avatar_url":"https://avatars2.githubusercontent.com/u/1335687?v=4","gravatar_id":"","url":"https://api.github.com/users/dmulcahey","html_url":"https://github.com/dmulcahey","followers_url":"https://api.github.com/users/dmulcahey/followers","following_url":"https://api.github.com/users/dmulcahey/following{/other_user}","gists_url":"https://api.github.com/users/dmulcahey/gists{/gist_id}","starred_url":"https://api.github.com/users/dmulcahey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmulcahey/subscriptions","organizations_url":"https://api.github.com/users/dmulcahey/orgs","repos_url":"https://api.github.com/users/dmulcahey/repos","events_url":"https://api.github.com/users/dmulcahey/events{/privacy}","received_events_url":"https://api.github.com/users/dmulcahey/received_events","type":"User","site_admin":false},"body":"Add a battery sensor to ZHA","created_at":"2018-12-17T01:00:29Z","updated_at":"2018-12-21T22:06:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"208c075ea4117b781155903d42cbb6db5a1435e0","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":527871105,"node_id":"MDU6TGFiZWw1Mjc4NzExMDU=","url":"https://api.github.com/repos/home-assistant/home-assistant/labels/cla-signed","name":"cla-signed","color":"008000","default":false},{"id":548457122,"node_id":"MDU6TGFiZWw1NDg0NTcxMjI=","url":"https://api.github.com/repos/home-assistant/home-assistant/labels/component:%20zha","name":"component: zha","color":"ededed","default":false},{"id":955422305,"node_id":"MDU6TGFiZWw5NTU0MjIzMDU=","url":"https://api.github.com/repos/home-assistant/home-assistant/labels/in%20progress","name":"in progress","color":"ededed","default":false},{"id":548457120,"node_id":"MDU6TGFiZWw1NDg0NTcxMjA=","url":"https://api.github.com/repos/home-assistant/home-assistant/labels/platform:%20sensor.zha","name":"platform: sensor.zha","color":"ededed","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/19363/commits","review_comments_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/19363/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/19363/comments","statuses_url":"https://api.github.com/repos/home-assistant/home-assistant/statuses/0fe3a56b210f5b4625aa5529e363fc3f071656b5","head":{"label":"dmulcahey:dm/zha-battery-sensor","ref":"dm/zha-battery-sensor","sha":"0fe3a56b210f5b4625aa5529e363fc3f071656b5","user":{"login":"dmulcahey","id":1335687,"node_id":"MDQ6VXNlcjEzMzU2ODc=","avatar_url":"https://avatars2.githubusercontent.com/u/1335687?v=4","gravatar_id":"","url":"https://api.github.com/users/dmulcahey","html_url":"https://github.com/dmulcahey","followers_url":"https://api.github.com/users/dmulcahey/followers","following_url":"https://api.github.com/users/dmulcahey/following{/other_user}","gists_url":"https://api.github.com/users/dmulcahey/gists{/gist_id}","starred_url":"https://api.github.com/users/dmulcahey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmulcahey/subscriptions","organizations_url":"https://api.github.com/users/dmulcahey/orgs","repos_url":"https://api.github.com/users/dmulcahey/repos","events_url":"https://api.github.com/users/dmulcahey/events{/privacy}","received_events_url":"https://api.github.com/users/dmulcahey/received_events","type":"User","site_admin":false},"repo":{"id":121896602,"node_id":"MDEwOlJlcG9zaXRvcnkxMjE4OTY2MDI=","name":"home-assistant","full_name":"dmulcahey/home-assistant","private":false,"owner":{"login":"dmulcahey","id":1335687,"node_id":"MDQ6VXNlcjEzMzU2ODc=","avatar_url":"https://avatars2.githubusercontent.com/u/1335687?v=4","gravatar_id":"","url":"https://api.github.com/users/dmulcahey","html_url":"https://github.com/dmulcahey","followers_url":"https://api.github.com/users/dmulcahey/followers","following_url":"https://api.github.com/users/dmulcahey/following{/other_user}","gists_url":"https://api.github.com/users/dmulcahey/gists{/gist_id}","starred_url":"https://api.github.com/users/dmulcahey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmulcahey/subscriptions","organizations_url":"https://api.github.com/users/dmulcahey/orgs","repos_url":"https://api.github.com/users/dmulcahey/repos","events_url":"https://api.github.com/users/dmulcahey/events{/privacy}","received_events_url":"https://api.github.com/users/dmulcahey/received_events","type":"User","site_admin":false},"html_url":"https://github.com/dmulcahey/home-assistant","description":":house_with_garden: Open-source home automation platform running on Python 3","fork":true,"url":"https://api.github.com/repos/dmulcahey/home-assistant","forks_url":"https://api.github.com/repos/dmulcahey/home-assistant/forks","keys_url":"https://api.github.com/repos/dmulcahey/home-assistant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dmulcahey/home-assistant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dmulcahey/home-assistant/teams","hooks_url":"https://api.github.com/repos/dmulcahey/home-assistant/hooks","issue_events_url":"https://api.github.com/repos/dmulcahey/home-assistant/issues/events{/number}","events_url":"https://api.github.com/repos/dmulcahey/home-assistant/events","assignees_url":"https://api.github.com/repos/dmulcahey/home-assistant/assignees{/user}","branches_url":"https://api.github.com/repos/dmulcahey/home-assistant/branches{/branch}","tags_url":"https://api.github.com/repos/dmulcahey/home-assistant/tags","blobs_url":"https://api.github.com/repos/dmulcahey/home-assistant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dmulcahey/home-assistant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dmulcahey/home-assistant/git/refs{/sha}","trees_url":"https://api.github.com/repos/dmulcahey/home-assistant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dmulcahey/home-assistant/statuses/{sha}","languages_url":"https://api.github.com/repos/dmulcahey/home-assistant/languages","stargazers_url":"https://api.github.com/repos/dmulcahey/home-assistant/stargazers","contributors_url":"https://api.github.com/repos/dmulcahey/home-assistant/contributors","subscribers_url":"https://api.github.com/repos/dmulcahey/home-assistant/subscribers","subscription_url":"https://api.github.com/repos/dmulcahey/home-assistant/subscription","commits_url":"https://api.github.com/repos/dmulcahey/home-assistant/commits{/sha}","git_commits_url":"https://api.github.com/repos/dmulcahey/home-assistant/git/commits{/sha}","comments_url":"https://api.github.com/repos/dmulcahey/home-assistant/comments{/number}","issue_comment_url":"https://api.github.com/repos/dmulcahey/home-assistant/issues/comments{/number}","contents_url":"https://api.github.com/repos/dmulcahey/home-assistant/contents/{+path}","compare_url":"https://api.github.com/repos/dmulcahey/home-assistant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dmulcahey/home-assistant/merges","archive_url":"https://api.github.com/repos/dmulcahey/home-assistant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dmulcahey/home-assistant/downloads","issues_url":"https://api.github.com/repos/dmulcahey/home-assistant/issues{/number}","pulls_url":"https://api.github.com/repos/dmulcahey/home-assistant/pulls{/number}","milestones_url":"https://api.github.com/repos/dmulcahey/home-assistant/milestones{/number}","notifications_url":"https://api.github.com/repos/dmulcahey/home-assistant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dmulcahey/home-assistant/labels{/name}","releases_url":"https://api.github.com/repos/dmulcahey/home-assistant/releases{/id}","deployments_url":"https://api.github.com/repos/dmulcahey/home-assistant/deployments","created_at":"2018-02-17T22:06:37Z","updated_at":"2018-12-17T00:48:52Z","pushed_at":"2018-12-20T19:06:05Z","git_url":"git://github.com/dmulcahey/home-assistant.git","ssh_url":"git@github.com:dmulcahey/home-assistant.git","clone_url":"https://github.com/dmulcahey/home-assistant.git","svn_url":"https://github.com/dmulcahey/home-assistant","homepage":"https://home-assistant.io","size":96768,"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":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"home-assistant:dev","ref":"dev","sha":"27ea59f6c3f88ffbec62c614454baab5971b579e","user":{"login":"home-assistant","id":13844975,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzODQ0OTc1","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,"node_id":"MDEwOlJlcG9zaXRvcnkxMjg4ODk5Mw==","name":"home-assistant","full_name":"home-assistant/home-assistant","private":false,"owner":{"login":"home-assistant","id":13844975,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzODQ0OTc1","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},"html_url":"https://github.com/home-assistant/home-assistant","description":":house_with_garden: Open source home automation that puts local control and privacy first","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":"2018-12-21T21:23:38Z","pushed_at":"2018-12-21T22:00:32Z","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://www.home-assistant.io","size":96003,"stargazers_count":19503,"watchers_count":19503,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5723,"mirror_url":null,"archived":false,"open_issues_count":923,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":5723,"open_issues":923,"watchers":19503,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/19363"},"html":{"href":"https://github.com/home-assistant/home-assistant/pull/19363"},"issue":{"href":"https://api.github.com/repos/home-assistant/home-assistant/issues/19363"},"comments":{"href":"https://api.github.com/repos/home-assistant/home-assistant/issues/19363/comments"},"review_comments":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/19363/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/19363/commits"},"statuses":{"href":"https://api.github.com/repos/home-assistant/home-assistant/statuses/0fe3a56b210f5b4625aa5529e363fc3f071656b5"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"Adminiuga"}}