{"action":"created","comment":{"url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments/63282648","id":63282648,"diff_hunk":"@@ -0,0 +1,85 @@\n+\"\"\"\n+Sensor for Last.fm account status.\n+\n+For more details about this platform, please refer to the documentation at\n+https://home-assistant.io/components/sensor.lastfm/\n+\"\"\"\n+import re\n+from homeassistant.helpers.entity import Entity\n+from homeassistant.const import CONF_API_KEY\n+\n+ICON = 'mdi:lastfm'\n+\n+REQUIREMENTS = ['pylast==1.6.0']\n+\n+\n+# pylint: disable=unused-argument\n+def setup_platform(hass, config, add_devices, discovery_info=None):\n+    \"\"\"Setup the Last.fm platform.\"\"\"\n+    import pylast as lastfm\n+    network = lastfm.LastFMNetwork(api_key=config.get(CONF_API_KEY),\n+                                   api_secret=config.get('api_secret'))\n+    add_devices(\n+        [LastfmSensor(username,\n+                      network) for username in config.get('users', [])])\n+\n+\n+class LastfmSensor(Entity):\n+    \"\"\"A class for the Last.fm account.\"\"\"\n+\n+    # pylint: disable=abstract-method\n+    def __init__(self, user, lastfm):\n+        \"\"\"Initialize the sensor.\"\"\"\n+        self._user = lastfm.get_user(user)\n+        self._name = user\n+        self._lastfm = lastfm\n+        self.update()\n+\n+    @property\n+    def name(self):\n+        \"\"\"Return the name of the sensor.\"\"\"\n+        return self._name\n+\n+    @property\n+    def entity_id(self):\n+        \"\"\"Return the entity ID.\"\"\"\n+        return 'sensor.lastfm_{}'.format(self._name)\n+\n+    @property\n+    def state(self):\n+        \"\"\"Return the state of the sensor.\"\"\"\n+        return self._state\n+\n+    # pylint: disable=no-member\n+    def update(self):\n+        \"\"\"Update device state.\"\"\"\n+        if self._user.get_now_playing() is None:\n+            self._state = \"Not Scrobbling\"\n+        else:\n+            now = self._user.get_now_playing()\n+            self._state = (str(now.artist) + \" - \" + now.title)\n+        self._playcount = self._user.get_playcount()\n+        last = self._user.get_recent_tracks(limit=2)[0]\n+        self._lastplayed = (str(last.track.artist) + \" - \" +\n+                            last.track.title)\n+        top = self._user.get_top_tracks(limit=1)\n+        toptitle = re.search(\"', '(.+?)',\", str(top))\n+        topartist = re.search(\"'(.+?)',\", str(top))","path":"homeassistant/components/sensor/lastfm.py","position":67,"original_position":67,"commit_id":"dc98c6e6a50e55dd23a2dccf881c005c16e76c24","original_commit_id":"dc98c6e6a50e55dd23a2dccf881c005c16e76c24","user":{"login":"robbiet480","id":18516,"avatar_url":"https://avatars.githubusercontent.com/u/18516?v=3","gravatar_id":"","url":"https://api.github.com/users/robbiet480","html_url":"https://github.com/robbiet480","followers_url":"https://api.github.com/users/robbiet480/followers","following_url":"https://api.github.com/users/robbiet480/following{/other_user}","gists_url":"https://api.github.com/users/robbiet480/gists{/gist_id}","starred_url":"https://api.github.com/users/robbiet480/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robbiet480/subscriptions","organizations_url":"https://api.github.com/users/robbiet480/orgs","repos_url":"https://api.github.com/users/robbiet480/repos","events_url":"https://api.github.com/users/robbiet480/events{/privacy}","received_events_url":"https://api.github.com/users/robbiet480/received_events","type":"User","site_admin":false},"body":"Hmmmm, you may want to look at what pylast is doing, because the Last.FM API exposes the title and artist to you directly without needing to do regex http://www.last.fm/api/show/user.getTopTracks","created_at":"2016-05-14T21:52:47Z","updated_at":"2016-05-14T21:52:47Z","html_url":"https://github.com/home-assistant/home-assistant/pull/2071#discussion_r63282648","pull_request_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/2071","_links":{"self":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments/63282648"},"html":{"href":"https://github.com/home-assistant/home-assistant/pull/2071#discussion_r63282648"},"pull_request":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/2071"}}},"pull_request":{"url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/2071","id":70104060,"html_url":"https://github.com/home-assistant/home-assistant/pull/2071","diff_url":"https://github.com/home-assistant/home-assistant/pull/2071.diff","patch_url":"https://github.com/home-assistant/home-assistant/pull/2071.patch","issue_url":"https://api.github.com/repos/home-assistant/home-assistant/issues/2071","number":2071,"state":"open","locked":false,"title":"Last.fm sensor","user":{"login":"GreenTurtwig","id":15905797,"avatar_url":"https://avatars.githubusercontent.com/u/15905797?v=3","gravatar_id":"","url":"https://api.github.com/users/GreenTurtwig","html_url":"https://github.com/GreenTurtwig","followers_url":"https://api.github.com/users/GreenTurtwig/followers","following_url":"https://api.github.com/users/GreenTurtwig/following{/other_user}","gists_url":"https://api.github.com/users/GreenTurtwig/gists{/gist_id}","starred_url":"https://api.github.com/users/GreenTurtwig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GreenTurtwig/subscriptions","organizations_url":"https://api.github.com/users/GreenTurtwig/orgs","repos_url":"https://api.github.com/users/GreenTurtwig/repos","events_url":"https://api.github.com/users/GreenTurtwig/events{/privacy}","received_events_url":"https://api.github.com/users/GreenTurtwig/received_events","type":"User","site_admin":false},"body":"**Description:** Adds a Last.fm sensor made by me and @darookee that reports back the currently scrobbling song, amount of plays, recent song and top song of users.\r\n![](http://puu.sh/oRUP2/1ab67954e9.png)\r\n\r\n**Example entry for `configuration.yaml` (if applicable):**\r\n```yaml\r\nsensor:\r\n  platform: lastfm\r\n  api_key: \"[API Key]\"\r\n  api_secret: \"[API Secret]\"\r\n  users:\r\n    - GreenTurtwig\r\n```\r\n\r\n**Checklist:**\r\n\r\nIf code communicates with devices:\r\n  - [x] Local tests with `tox` run successfully. **Your PR cannot be merged unless tests pass**\r\n  - [x] New dependencies have been added to the `REQUIREMENTS` variable ([example][ex-requir]).\r\n  - [x] New dependencies are only imported inside functions that use them ([example][ex-import]).\r\n  - [x] New dependencies have been added to `requirements_all.txt` by running `script/gen_requirements_all.py`.\r\n  - [x] New files were added to `.coveragerc`.","created_at":"2016-05-14T21:12:32Z","updated_at":"2016-05-14T21:52:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"90fdd7994cad40f3a0269f6a9a4e3a6fbac09b84","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/2071/commits","review_comments_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/2071/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/2071/comments","statuses_url":"https://api.github.com/repos/home-assistant/home-assistant/statuses/dc98c6e6a50e55dd23a2dccf881c005c16e76c24","head":{"label":"GreenTurtwig:lastfm","ref":"lastfm","sha":"dc98c6e6a50e55dd23a2dccf881c005c16e76c24","user":{"login":"GreenTurtwig","id":15905797,"avatar_url":"https://avatars.githubusercontent.com/u/15905797?v=3","gravatar_id":"","url":"https://api.github.com/users/GreenTurtwig","html_url":"https://github.com/GreenTurtwig","followers_url":"https://api.github.com/users/GreenTurtwig/followers","following_url":"https://api.github.com/users/GreenTurtwig/following{/other_user}","gists_url":"https://api.github.com/users/GreenTurtwig/gists{/gist_id}","starred_url":"https://api.github.com/users/GreenTurtwig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GreenTurtwig/subscriptions","organizations_url":"https://api.github.com/users/GreenTurtwig/orgs","repos_url":"https://api.github.com/users/GreenTurtwig/repos","events_url":"https://api.github.com/users/GreenTurtwig/events{/privacy}","received_events_url":"https://api.github.com/users/GreenTurtwig/received_events","type":"User","site_admin":false},"repo":{"id":55912867,"name":"home-assistant","full_name":"GreenTurtwig/home-assistant","owner":{"login":"GreenTurtwig","id":15905797,"avatar_url":"https://avatars.githubusercontent.com/u/15905797?v=3","gravatar_id":"","url":"https://api.github.com/users/GreenTurtwig","html_url":"https://github.com/GreenTurtwig","followers_url":"https://api.github.com/users/GreenTurtwig/followers","following_url":"https://api.github.com/users/GreenTurtwig/following{/other_user}","gists_url":"https://api.github.com/users/GreenTurtwig/gists{/gist_id}","starred_url":"https://api.github.com/users/GreenTurtwig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GreenTurtwig/subscriptions","organizations_url":"https://api.github.com/users/GreenTurtwig/orgs","repos_url":"https://api.github.com/users/GreenTurtwig/repos","events_url":"https://api.github.com/users/GreenTurtwig/events{/privacy}","received_events_url":"https://api.github.com/users/GreenTurtwig/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/GreenTurtwig/home-assistant","description":":house_with_garden: Open-source home automation platform running on Python 3","fork":true,"url":"https://api.github.com/repos/GreenTurtwig/home-assistant","forks_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/forks","keys_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/teams","hooks_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/hooks","issue_events_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/issues/events{/number}","events_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/events","assignees_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/assignees{/user}","branches_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/branches{/branch}","tags_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/tags","blobs_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/git/refs{/sha}","trees_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/statuses/{sha}","languages_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/languages","stargazers_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/stargazers","contributors_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/contributors","subscribers_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/subscribers","subscription_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/subscription","commits_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/commits{/sha}","git_commits_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/git/commits{/sha}","comments_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/comments{/number}","issue_comment_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/issues/comments{/number}","contents_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/contents/{+path}","compare_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/merges","archive_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/downloads","issues_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/issues{/number}","pulls_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/pulls{/number}","milestones_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/milestones{/number}","notifications_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/labels{/name}","releases_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/releases{/id}","deployments_url":"https://api.github.com/repos/GreenTurtwig/home-assistant/deployments","created_at":"2016-04-10T17:27:52Z","updated_at":"2016-04-10T17:27:55Z","pushed_at":"2016-05-14T21:29:24Z","git_url":"git://github.com/GreenTurtwig/home-assistant.git","ssh_url":"git@github.com:GreenTurtwig/home-assistant.git","clone_url":"https://github.com/GreenTurtwig/home-assistant.git","svn_url":"https://github.com/GreenTurtwig/home-assistant","homepage":"https://home-assistant.io","size":55190,"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":"0adc8537416d787ad5f3881f0ff84600f256818d","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-05-14T21:04:27Z","pushed_at":"2016-05-14T21:29:24Z","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":67492,"stargazers_count":3345,"watchers_count":3345,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":673,"mirror_url":null,"open_issues_count":157,"forks":673,"open_issues":157,"watchers":3345,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/2071"},"html":{"href":"https://github.com/home-assistant/home-assistant/pull/2071"},"issue":{"href":"https://api.github.com/repos/home-assistant/home-assistant/issues/2071"},"comments":{"href":"https://api.github.com/repos/home-assistant/home-assistant/issues/2071/comments"},"review_comments":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/2071/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/2071/commits"},"statuses":{"href":"https://api.github.com/repos/home-assistant/home-assistant/statuses/dc98c6e6a50e55dd23a2dccf881c005c16e76c24"}}}}