{"action":"created","comment":{"url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments/84909340","pull_request_review_id":5656296,"id":84909340,"diff_hunk":"@@ -0,0 +1,194 @@\n+\"\"\"\n+Support for mipow lights.\n+For more details about this platform, please refer to the documentation at\n+https://home-assistant.io/components/light.mipow/\n+\"\"\"\n+\n+import logging\n+from homeassistant.components.light import (\n+    ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_EFFECT, EFFECT_RAINBOW, EFFECT_CANDLE, ATTR_FLASH, FLASH_LONG, FLASH_SHORT, Light)\n+from homeassistant.loader import get_component\n+_LOGGER = logging.getLogger(__name__)\n+\n+REQUIREMENTS = ['pygatt[GATTTOOL]==3.0.0', 'pexpect==4.0.1']\n+# pylint: disable=unused-argument\n+def setup_platform(hass, config, add_devices_callback, discovery_info=None):\n+    \"\"\"Add device specified by serial number.\"\"\"\n+    serial = config['serial']\n+    name = config.get('name')\n+    bulb = Mipow(serial, name)\n+\n+    add_devices_callback([bulb])\n+\n+\n+class Mipow(Light):\n+    def __init__(self, serial, name=None):\n+        import pygatt\n+        \"\"\"Initialize the light.\"\"\"\n+        if name is not None:\n+            self._name = name\n+        else:\n+            self._name = serial\n+\n+        self._serial = serial\n+        self._adapter = None\n+        self._connection = None\n+        try:\n+            self.update()\n+        except:\n+            self._rgb_color = [0, 0, 0]\n+            self._rgb_bright = [0]\n+\n+    def update(self):\n+        \"\"\"Read back the device state.\"\"\"\n+        self._rgb_color = self.rgb_color\n+        self._rgb_bright = self.rgb_bright\n+\n+    def _start_adapter(self):\n+        import pygatt\n+        if self._adapter is not None:\n+            self._adapter.stop()\n+\n+        adapter = pygatt.backends.GATTToolBackend()\n+        adapter.start()\n+\n+        self._adapter = adapter\n+\n+        return adapter\n+\n+    def _stop_adapter(self):\n+        self._adapter.stop()\n+        \n+\n+    def isconnected(self):\n+        if device._connected == True:\n+            if adapter.address == self._serial:\n+                return True\n+        else:\n+            return False\n+    def connect(self):\n+        import pygatt\n+        if self._connection is not None:\n+            if self._connection._connected:\n+                return self._connection\n+        else:\n+            if self._adapter is not None:\n+                self._adapter.stop()\n+\n+            adapter = pygatt.backends.GATTToolBackend()\n+            adapter.start()\n+\n+            self._adapter = adapter\n+            self._connection = self._adapter.connect(self._serial)\n+            return self._connection\n+\n+    @property\n+    def should_poll(self):\n+        \"\"\"Polling needed.\"\"\"\n+        return True\n+\n+    @property\n+    def name(self):\n+        \"\"\"Return the name of the light.\"\"\"\n+        return self._name\n+\n+    @property\n+    def rgb_color(self):\n+# Get device status from gattools\n+        self._connection = self.connect()\n+\n+        device_status = self._connection.char_read(\"0000fffc-0000-1000-8000-00805f9b34fb\")\n+\n+#Convert byte array into int list\n+        device_colors = [x for x in device_status]\n+\n+# Remove first element as it's the brightness\n+        device_colors.pop(0)\n+\n+# Assign to instance for later use\n+        self._rgb_color = device_colors\n+\n+\n+# Return list for ha use\n+        return self._rgb_color\n+    @property\n+    def rgb_bright(self):\n+# Get device status from gattools\n+        self._connection = self.connect()\n+\n+        device_status = self._connection.char_read(\"0000fffc-0000-1000-8000-00805f9b34fb\")\n+\n+#Convert byte array into int list\n+        device_bright = [x for x in device_status]\n+\n+# Remove first element as it's the brightness\n+        device_bright.pop()\n+        device_bright.pop()\n+        device_bright.pop()\n+# Assign to instance for later use\n+        self._rgb_bright = device_bright\n+\n+# Return list for ha use\n+        return self._rgb_bright\n+    @property\n+    def brightness(self):\n+        return self._rgb_bright\n+    @property\n+    def is_on(self):\n+        \"\"\"Check whether any of the LEDs colors are non-zero.\"\"\"\n+        return sum(self._rgb_color)+sum(self._rgb_bright) > 0\n+\n+    def turn_on(self, **kwargs):\n+        \"\"\"Turn the device on.\"\"\"\n+        self._connection = self.connect()\n+\n+        if ATTR_BRIGHTNESS in kwargs and ATTR_RGB_COLOR in kwargs and not ATTR_FLASH in kwargs:\n+            self._rgb_color = [x for x in kwargs[ATTR_RGB_COLOR]]\n+            brgb = [kwargs[ATTR_BRIGHTNESS], self._rgb_color[0], self._rgb_color[1], self._rgb_color[2]]\n+\n+            self._connection.char_write_handle(0x0025, brgb)\n+        elif ATTR_RGB_COLOR in kwargs and not ATTR_BRIGHTNESS in kwargs and not ATTR_FLASH in kwargs:","path":"homeassistant/components/light/mipow.py","position":150,"original_position":150,"commit_id":"a6d1fd68ab4bfcb1b924141153b7375000e5c752","original_commit_id":"a6d1fd68ab4bfcb1b924141153b7375000e5c752","user":{"login":"balloobbot","id":16367972,"avatar_url":"https://avatars.githubusercontent.com/u/16367972?v=3","gravatar_id":"","url":"https://api.github.com/users/balloobbot","html_url":"https://github.com/balloobbot","followers_url":"https://api.github.com/users/balloobbot/followers","following_url":"https://api.github.com/users/balloobbot/following{/other_user}","gists_url":"https://api.github.com/users/balloobbot/gists{/gist_id}","starred_url":"https://api.github.com/users/balloobbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/balloobbot/subscriptions","organizations_url":"https://api.github.com/users/balloobbot/orgs","repos_url":"https://api.github.com/users/balloobbot/repos","events_url":"https://api.github.com/users/balloobbot/events{/privacy}","received_events_url":"https://api.github.com/users/balloobbot/received_events","type":"User","site_admin":false},"body":"_[farcy v1.1](https://github.com/appfolio/farcy)_\n* 43: E713 test for membership should be 'not in'\n* 80: E501 line too long (101 > 79 characters)","created_at":"2016-10-25T14:01:57Z","updated_at":"2016-10-25T14:01:57Z","html_url":"https://github.com/home-assistant/home-assistant/pull/4043#discussion_r84909340","pull_request_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/4043","_links":{"self":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments/84909340"},"html":{"href":"https://github.com/home-assistant/home-assistant/pull/4043#discussion_r84909340"},"pull_request":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/4043"}}},"pull_request":{"url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/4043","id":90813872,"html_url":"https://github.com/home-assistant/home-assistant/pull/4043","diff_url":"https://github.com/home-assistant/home-assistant/pull/4043.diff","patch_url":"https://github.com/home-assistant/home-assistant/pull/4043.patch","issue_url":"https://api.github.com/repos/home-assistant/home-assistant/issues/4043","number":4043,"state":"open","locked":false,"title":"Support for Mipow smart bulb","user":{"login":"amahlaka","id":13930236,"avatar_url":"https://avatars.githubusercontent.com/u/13930236?v=3","gravatar_id":"","url":"https://api.github.com/users/amahlaka","html_url":"https://github.com/amahlaka","followers_url":"https://api.github.com/users/amahlaka/followers","following_url":"https://api.github.com/users/amahlaka/following{/other_user}","gists_url":"https://api.github.com/users/amahlaka/gists{/gist_id}","starred_url":"https://api.github.com/users/amahlaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amahlaka/subscriptions","organizations_url":"https://api.github.com/users/amahlaka/orgs","repos_url":"https://api.github.com/users/amahlaka/repos","events_url":"https://api.github.com/users/amahlaka/events{/privacy}","received_events_url":"https://api.github.com/users/amahlaka/received_events","type":"User","site_admin":false},"body":"**Description:**\r\n\r\n\r\n**Related issue (if applicable):** fixes #<home-assistant issue number goes here>\r\n\r\n**Pull request in [home-assistant.github.io](https://github.com/home-assistant/home-assistant.github.io) with documentation (if applicable):** home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>\r\n\r\n**Example entry for `configuration.yaml` (if applicable):**\r\n```yaml\r\nlight:\r\n  platform: mipow\r\n  name: room\r\n  serial: '55:37:4B:12:AC:E6'\r\n```\r\n\r\n**Checklist:**\r\n\r\nIf user exposed functionality or configuration variables are added/changed:\r\n  - [ ] Documentation added/updated in [home-assistant.github.io](https://github.com/home-assistant/home-assistant.github.io)\r\n\r\nIf the code communicates with devices, web services, or third-party tools:\r\n  - [ ] Local tests with `tox` run successfully. **Your PR cannot be merged unless tests pass**\r\n  - [ ] New dependencies have been added to the `REQUIREMENTS` variable ([example][ex-requir]).\r\n  - [ ] New dependencies are only imported inside functions that use them ([example][ex-import]).\r\n  - [ ] New dependencies have been added to `requirements_all.txt` by running `script/gen_requirements_all.py`.\r\n  - [ ] New files were added to `.coveragerc`.\r\n\r\nIf the code does not interact with devices:\r\n  - [ ] Local tests with `tox` run successfully. **Your PR cannot be merged unless tests pass**\r\n  - [ ] Tests have been added to verify that the new code works.\r\n\r\n[ex-requir]: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/keyboard.py#L16\r\n[ex-import]: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/keyboard.py#L51\r\n\r\n","created_at":"2016-10-25T14:01:19Z","updated_at":"2016-10-25T14:01:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1188f3f576fe996c25336bbd80ffdbe870288db4","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/4043/commits","review_comments_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/4043/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/4043/comments","statuses_url":"https://api.github.com/repos/home-assistant/home-assistant/statuses/a6d1fd68ab4bfcb1b924141153b7375000e5c752","head":{"label":"amahlaka:MipowComp","ref":"MipowComp","sha":"a6d1fd68ab4bfcb1b924141153b7375000e5c752","user":{"login":"amahlaka","id":13930236,"avatar_url":"https://avatars.githubusercontent.com/u/13930236?v=3","gravatar_id":"","url":"https://api.github.com/users/amahlaka","html_url":"https://github.com/amahlaka","followers_url":"https://api.github.com/users/amahlaka/followers","following_url":"https://api.github.com/users/amahlaka/following{/other_user}","gists_url":"https://api.github.com/users/amahlaka/gists{/gist_id}","starred_url":"https://api.github.com/users/amahlaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amahlaka/subscriptions","organizations_url":"https://api.github.com/users/amahlaka/orgs","repos_url":"https://api.github.com/users/amahlaka/repos","events_url":"https://api.github.com/users/amahlaka/events{/privacy}","received_events_url":"https://api.github.com/users/amahlaka/received_events","type":"User","site_admin":false},"repo":{"id":71873657,"name":"home-assistant","full_name":"amahlaka/home-assistant","owner":{"login":"amahlaka","id":13930236,"avatar_url":"https://avatars.githubusercontent.com/u/13930236?v=3","gravatar_id":"","url":"https://api.github.com/users/amahlaka","html_url":"https://github.com/amahlaka","followers_url":"https://api.github.com/users/amahlaka/followers","following_url":"https://api.github.com/users/amahlaka/following{/other_user}","gists_url":"https://api.github.com/users/amahlaka/gists{/gist_id}","starred_url":"https://api.github.com/users/amahlaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amahlaka/subscriptions","organizations_url":"https://api.github.com/users/amahlaka/orgs","repos_url":"https://api.github.com/users/amahlaka/repos","events_url":"https://api.github.com/users/amahlaka/events{/privacy}","received_events_url":"https://api.github.com/users/amahlaka/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/amahlaka/home-assistant","description":":house_with_garden: Open-source home automation platform running on Python 3","fork":true,"url":"https://api.github.com/repos/amahlaka/home-assistant","forks_url":"https://api.github.com/repos/amahlaka/home-assistant/forks","keys_url":"https://api.github.com/repos/amahlaka/home-assistant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amahlaka/home-assistant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amahlaka/home-assistant/teams","hooks_url":"https://api.github.com/repos/amahlaka/home-assistant/hooks","issue_events_url":"https://api.github.com/repos/amahlaka/home-assistant/issues/events{/number}","events_url":"https://api.github.com/repos/amahlaka/home-assistant/events","assignees_url":"https://api.github.com/repos/amahlaka/home-assistant/assignees{/user}","branches_url":"https://api.github.com/repos/amahlaka/home-assistant/branches{/branch}","tags_url":"https://api.github.com/repos/amahlaka/home-assistant/tags","blobs_url":"https://api.github.com/repos/amahlaka/home-assistant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amahlaka/home-assistant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amahlaka/home-assistant/git/refs{/sha}","trees_url":"https://api.github.com/repos/amahlaka/home-assistant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amahlaka/home-assistant/statuses/{sha}","languages_url":"https://api.github.com/repos/amahlaka/home-assistant/languages","stargazers_url":"https://api.github.com/repos/amahlaka/home-assistant/stargazers","contributors_url":"https://api.github.com/repos/amahlaka/home-assistant/contributors","subscribers_url":"https://api.github.com/repos/amahlaka/home-assistant/subscribers","subscription_url":"https://api.github.com/repos/amahlaka/home-assistant/subscription","commits_url":"https://api.github.com/repos/amahlaka/home-assistant/commits{/sha}","git_commits_url":"https://api.github.com/repos/amahlaka/home-assistant/git/commits{/sha}","comments_url":"https://api.github.com/repos/amahlaka/home-assistant/comments{/number}","issue_comment_url":"https://api.github.com/repos/amahlaka/home-assistant/issues/comments{/number}","contents_url":"https://api.github.com/repos/amahlaka/home-assistant/contents/{+path}","compare_url":"https://api.github.com/repos/amahlaka/home-assistant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amahlaka/home-assistant/merges","archive_url":"https://api.github.com/repos/amahlaka/home-assistant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amahlaka/home-assistant/downloads","issues_url":"https://api.github.com/repos/amahlaka/home-assistant/issues{/number}","pulls_url":"https://api.github.com/repos/amahlaka/home-assistant/pulls{/number}","milestones_url":"https://api.github.com/repos/amahlaka/home-assistant/milestones{/number}","notifications_url":"https://api.github.com/repos/amahlaka/home-assistant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amahlaka/home-assistant/labels{/name}","releases_url":"https://api.github.com/repos/amahlaka/home-assistant/releases{/id}","deployments_url":"https://api.github.com/repos/amahlaka/home-assistant/deployments","created_at":"2016-10-25T08:02:27Z","updated_at":"2016-10-25T08:02:32Z","pushed_at":"2016-10-25T13:58:37Z","git_url":"git://github.com/amahlaka/home-assistant.git","ssh_url":"git@github.com:amahlaka/home-assistant.git","clone_url":"https://github.com/amahlaka/home-assistant.git","svn_url":"https://github.com/amahlaka/home-assistant","homepage":"https://home-assistant.io","size":42276,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"home-assistant:dev","ref":"dev","sha":"a8c5c995a0acedbe99bc59304206733a90c6fe59","user":{"login":"home-assistant","id":13844975,"avatar_url":"https://avatars.githubusercontent.com/u/13844975?v=3","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,"name":"home-assistant","full_name":"home-assistant/home-assistant","owner":{"login":"home-assistant","id":13844975,"avatar_url":"https://avatars.githubusercontent.com/u/13844975?v=3","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},"private":false,"html_url":"https://github.com/home-assistant/home-assistant","description":":house_with_garden: Open-source home automation platform running on Python 3","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":"2016-10-25T13:44:00Z","pushed_at":"2016-10-25T14:01:19Z","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://home-assistant.io","size":84319,"stargazers_count":4404,"watchers_count":4404,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1143,"mirror_url":null,"open_issues_count":308,"forks":1143,"open_issues":308,"watchers":4404,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/4043"},"html":{"href":"https://github.com/home-assistant/home-assistant/pull/4043"},"issue":{"href":"https://api.github.com/repos/home-assistant/home-assistant/issues/4043"},"comments":{"href":"https://api.github.com/repos/home-assistant/home-assistant/issues/4043/comments"},"review_comments":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/4043/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/4043/commits"},"statuses":{"href":"https://api.github.com/repos/home-assistant/home-assistant/statuses/a6d1fd68ab4bfcb1b924141153b7375000e5c752"}}}}
{"actor":{"display_login":"balloobbot"}}