{"action":"created","comment":{"url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments/71269876","id":71269876,"diff_hunk":"@@ -43,16 +46,86 @@\n SUPPORT_SOURCE_TV = 'TV'\n SUPPORT_SOURCE_RADIO = 'Radio'\n \n+# Service call validation schemas\n+SONOS_SCHEMA = vol.Schema({\n+    ATTR_ENTITY_ID: cv.entity_ids,\n+})\n+\n+SONOS_SET_TIMER_SCHEMA = SONOS_SCHEMA.extend({\n+    vol.Required(ATTR_SLEEP_TIME): cv.positive_int,\n+})\n+\n+#List of devices that have been registered\n+devices=[]\n \n # pylint: disable=unused-argument, too-many-locals\n def setup_platform(hass, config, add_devices, discovery_info=None):\n     \"\"\"Setup the Sonos platform.\"\"\"\n     import soco\n+    global devices\n+\n+    def register_services():\n+        def _apply_service(service, service_func, *service_func_args):\n+            \"\"\"Internal func for applying a service.\"\"\"\n+            entity_ids = service.data.get('entity_id')\n+\n+            if entity_ids:\n+                _devices = [device for device in devices\n+                            if device.entity_id in entity_ids]\n+            else:\n+                _devices = devices\n+\n+            for device in _devices:\n+                service_func(device, *service_func_args)\n+                device.update_ha_state(True)\n+\n+        def group_players_service(service):\n+            \"\"\"Group media players, use player as coordinator.\"\"\"\n+            _apply_service(service, SonosDevice.group_players)\n+\n+        def unjoin_service(service):\n+            \"\"\"Unjoin the player from a group.\"\"\"\n+            _apply_service(service, SonosDevice.unjoin)\n+\n+        def snapshot_service(service):\n+            \"\"\"Take a snapshot.\"\"\"\n+            _apply_service(service, SonosDevice.snapshot)\n+\n+        def restore_service(service):\n+            \"\"\"Restore a snapshot.\"\"\"\n+            _apply_service(service, SonosDevice.restore)\n+\n+        descriptions = load_yaml_config_file(\n+            path.join(path.dirname(__file__), 'services.yaml'))\n+\n+        hass.services.register(DOMAIN, SERVICE_GROUP_PLAYERS,\n+                               group_players_service,\n+                               descriptions.get(SERVICE_GROUP_PLAYERS),\n+                               schema=SONOS_SCHEMA)\n+\n+        hass.services.register(DOMAIN, SERVICE_UNJOIN,\n+                               unjoin_service,\n+                               descriptions.get(SERVICE_UNJOIN),\n+                               schema=SONOS_SCHEMA)\n+\n+        hass.services.register(DOMAIN, SERVICE_SNAPSHOT,\n+                               snapshot_service,\n+                               descriptions.get(SERVICE_SNAPSHOT),\n+                               schema=SONOS_SCHEMA)\n+\n+        hass.services.register(DOMAIN, SERVICE_RESTORE,\n+                               restore_service,\n+                               descriptions.get(SERVICE_RESTORE),\n+                               schema=SONOS_SCHEMA)\n \n     if discovery_info:\n         player = soco.SoCo(discovery_info)\n         if player.is_visible:\n-            add_devices([SonosDevice(hass, player)])\n+            device=SonosDevice(hass, player)","path":"homeassistant/components/media_player/sonos.py","position":100,"original_position":100,"commit_id":"1accee8b261aeef49b6e7b1bd4438337e5160529","original_commit_id":"1accee8b261aeef49b6e7b1bd4438337e5160529","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* 19: E225 missing whitespace around operator","created_at":"2016-07-19T04:01:55Z","updated_at":"2016-07-19T04:01:55Z","html_url":"https://github.com/home-assistant/home-assistant/pull/2558#discussion_r71269876","pull_request_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/2558","_links":{"self":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/comments/71269876"},"html":{"href":"https://github.com/home-assistant/home-assistant/pull/2558#discussion_r71269876"},"pull_request":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/2558"}}},"pull_request":{"url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/2558","id":77914814,"html_url":"https://github.com/home-assistant/home-assistant/pull/2558","diff_url":"https://github.com/home-assistant/home-assistant/pull/2558.diff","patch_url":"https://github.com/home-assistant/home-assistant/pull/2558.patch","issue_url":"https://api.github.com/repos/home-assistant/home-assistant/issues/2558","number":2558,"state":"open","locked":false,"title":"Fix services registration, and adding schema util to sonos","user":{"login":"americanwookie","id":618191,"avatar_url":"https://avatars.githubusercontent.com/u/618191?v=3","gravatar_id":"","url":"https://api.github.com/users/americanwookie","html_url":"https://github.com/americanwookie","followers_url":"https://api.github.com/users/americanwookie/followers","following_url":"https://api.github.com/users/americanwookie/following{/other_user}","gists_url":"https://api.github.com/users/americanwookie/gists{/gist_id}","starred_url":"https://api.github.com/users/americanwookie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/americanwookie/subscriptions","organizations_url":"https://api.github.com/users/americanwookie/orgs","repos_url":"https://api.github.com/users/americanwookie/repos","events_url":"https://api.github.com/users/americanwookie/events{/privacy}","received_events_url":"https://api.github.com/users/americanwookie/received_events","type":"User","site_admin":false},"body":"**Description:**\r\nCurrently sonos_* services aren't registered if netdisco discovery is used for devices. This PR moves service registration into a def, sets up a global list of all known devices, and tries to invoke service registration as little as necessary. This PR also includes adding schema use to sonos.","created_at":"2016-07-19T04:01:44Z","updated_at":"2016-07-19T04:01:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fb64f23929da1a7d60ce1b417e69e393064438bb","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/2558/commits","review_comments_url":"https://api.github.com/repos/home-assistant/home-assistant/pulls/2558/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/2558/comments","statuses_url":"https://api.github.com/repos/home-assistant/home-assistant/statuses/1accee8b261aeef49b6e7b1bd4438337e5160529","head":{"label":"americanwookie:sonos_fix_registration","ref":"sonos_fix_registration","sha":"1accee8b261aeef49b6e7b1bd4438337e5160529","user":{"login":"americanwookie","id":618191,"avatar_url":"https://avatars.githubusercontent.com/u/618191?v=3","gravatar_id":"","url":"https://api.github.com/users/americanwookie","html_url":"https://github.com/americanwookie","followers_url":"https://api.github.com/users/americanwookie/followers","following_url":"https://api.github.com/users/americanwookie/following{/other_user}","gists_url":"https://api.github.com/users/americanwookie/gists{/gist_id}","starred_url":"https://api.github.com/users/americanwookie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/americanwookie/subscriptions","organizations_url":"https://api.github.com/users/americanwookie/orgs","repos_url":"https://api.github.com/users/americanwookie/repos","events_url":"https://api.github.com/users/americanwookie/events{/privacy}","received_events_url":"https://api.github.com/users/americanwookie/received_events","type":"User","site_admin":false},"repo":{"id":63566211,"name":"home-assistant","full_name":"americanwookie/home-assistant","owner":{"login":"americanwookie","id":618191,"avatar_url":"https://avatars.githubusercontent.com/u/618191?v=3","gravatar_id":"","url":"https://api.github.com/users/americanwookie","html_url":"https://github.com/americanwookie","followers_url":"https://api.github.com/users/americanwookie/followers","following_url":"https://api.github.com/users/americanwookie/following{/other_user}","gists_url":"https://api.github.com/users/americanwookie/gists{/gist_id}","starred_url":"https://api.github.com/users/americanwookie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/americanwookie/subscriptions","organizations_url":"https://api.github.com/users/americanwookie/orgs","repos_url":"https://api.github.com/users/americanwookie/repos","events_url":"https://api.github.com/users/americanwookie/events{/privacy}","received_events_url":"https://api.github.com/users/americanwookie/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/americanwookie/home-assistant","description":":house_with_garden: Open-source home automation platform running on Python 3","fork":true,"url":"https://api.github.com/repos/americanwookie/home-assistant","forks_url":"https://api.github.com/repos/americanwookie/home-assistant/forks","keys_url":"https://api.github.com/repos/americanwookie/home-assistant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/americanwookie/home-assistant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/americanwookie/home-assistant/teams","hooks_url":"https://api.github.com/repos/americanwookie/home-assistant/hooks","issue_events_url":"https://api.github.com/repos/americanwookie/home-assistant/issues/events{/number}","events_url":"https://api.github.com/repos/americanwookie/home-assistant/events","assignees_url":"https://api.github.com/repos/americanwookie/home-assistant/assignees{/user}","branches_url":"https://api.github.com/repos/americanwookie/home-assistant/branches{/branch}","tags_url":"https://api.github.com/repos/americanwookie/home-assistant/tags","blobs_url":"https://api.github.com/repos/americanwookie/home-assistant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/americanwookie/home-assistant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/americanwookie/home-assistant/git/refs{/sha}","trees_url":"https://api.github.com/repos/americanwookie/home-assistant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/americanwookie/home-assistant/statuses/{sha}","languages_url":"https://api.github.com/repos/americanwookie/home-assistant/languages","stargazers_url":"https://api.github.com/repos/americanwookie/home-assistant/stargazers","contributors_url":"https://api.github.com/repos/americanwookie/home-assistant/contributors","subscribers_url":"https://api.github.com/repos/americanwookie/home-assistant/subscribers","subscription_url":"https://api.github.com/repos/americanwookie/home-assistant/subscription","commits_url":"https://api.github.com/repos/americanwookie/home-assistant/commits{/sha}","git_commits_url":"https://api.github.com/repos/americanwookie/home-assistant/git/commits{/sha}","comments_url":"https://api.github.com/repos/americanwookie/home-assistant/comments{/number}","issue_comment_url":"https://api.github.com/repos/americanwookie/home-assistant/issues/comments{/number}","contents_url":"https://api.github.com/repos/americanwookie/home-assistant/contents/{+path}","compare_url":"https://api.github.com/repos/americanwookie/home-assistant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/americanwookie/home-assistant/merges","archive_url":"https://api.github.com/repos/americanwookie/home-assistant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/americanwookie/home-assistant/downloads","issues_url":"https://api.github.com/repos/americanwookie/home-assistant/issues{/number}","pulls_url":"https://api.github.com/repos/americanwookie/home-assistant/pulls{/number}","milestones_url":"https://api.github.com/repos/americanwookie/home-assistant/milestones{/number}","notifications_url":"https://api.github.com/repos/americanwookie/home-assistant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/americanwookie/home-assistant/labels{/name}","releases_url":"https://api.github.com/repos/americanwookie/home-assistant/releases{/id}","deployments_url":"https://api.github.com/repos/americanwookie/home-assistant/deployments","created_at":"2016-07-18T03:06:48Z","updated_at":"2016-07-18T03:06:51Z","pushed_at":"2016-07-19T04:01:16Z","git_url":"git://github.com/americanwookie/home-assistant.git","ssh_url":"git@github.com:americanwookie/home-assistant.git","clone_url":"https://github.com/americanwookie/home-assistant.git","svn_url":"https://github.com/americanwookie/home-assistant","homepage":"https://home-assistant.io","size":84355,"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":"32f228f984e1029d011e7de206538f39fdaae38d","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-07-18T21:58:23Z","pushed_at":"2016-07-19T04:01:44Z","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":92234,"stargazers_count":3721,"watchers_count":3721,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":827,"mirror_url":null,"open_issues_count":160,"forks":827,"open_issues":160,"watchers":3721,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/2558"},"html":{"href":"https://github.com/home-assistant/home-assistant/pull/2558"},"issue":{"href":"https://api.github.com/repos/home-assistant/home-assistant/issues/2558"},"comments":{"href":"https://api.github.com/repos/home-assistant/home-assistant/issues/2558/comments"},"review_comments":{"href":"https://api.github.com/repos/home-assistant/home-assistant/pulls/2558/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/2558/commits"},"statuses":{"href":"https://api.github.com/repos/home-assistant/home-assistant/statuses/1accee8b261aeef49b6e7b1bd4438337e5160529"}}}}
{"actor":{"display_login":"balloobbot"}}