def group(self, room, slaves): device = sonos.get_speaker(room) if slaves == "all": device.partymode() else: for slave in slaves.split(","): sonos.get_speaker(slave).join(device) return "Grouped the following speakers to " + device.player_name + ": " + slaves
def transfer(self, room, target): device = sonos.get_speaker(room) target = sonos.get_speaker(target) if device == target: raise Exception("Cannot transfer to the same device!") # Resolve coordinator device = device if from_device.is_coordinator else device.group()["coordinator"] if device == target: return "Devices are already playing the same thing!" target.join(device) device.unjoin() return "Transfer playback from " + device.player_name + " to " + target.player_name
def stop(self, room): device = sonos.get_speaker(room) device.stop() device.clear_queue() device.cross_fade = False device.play_mode = "NORMAL" try: device.switch_to_tv() except: pass return "Playback stopped in " + device.player_name
def play(self, room, radio=None, genre=None, album=None, artist=None, slaves=None): device = sonos.get_speaker(room) state = sonos.save_states([device]) if radio: response = device.get_favorite_radio_stations() for item in response.get("favorites"): if item["title"] == default_radio_station: sonos.fade_vol(device) device.stop() device.volume = state[device]["volume"] device.play_uri(item["uri"], "Radio") return "Playing " + item["title"] + " in " + device.player_name return "Could not find a matching radio station for: " + radio.lower() elif genre: if genre == "party": response = device.get_playlists() for playlist in response.get("item_list"): if playlist.title == party_playlist: # print playlist uri = sonos.get_speech_uri(start_message) sonos.fade_vol(device) device.clear_queue() device.stop() device.add_uri_to_queue(uri) device.add_to_queue(playlist) device.volume = state[device]["volume"] device.play_from_queue(0) device.play_mode = "SHUFFLE_NOREPEAT" device.cross_fade = True return "Playing party music in " + device.player_name else: genres = device.get_genres() for item in genres: if item.title.lower() == genre.lower(): sonos.play_library_item(device, state, item, play_mode="SHUFFLE", random_start=True) return "Playing " + item.title + " music in " + device.player_name return "Could not find a genre matching: " + genre.lower() elif album: albums = device.get_albums(max_items=1000) for item in albums: if item.title.lower() == album.lower(): sonos.play_library_item(device, state, item) return "Playing " + item.title + " in " + device.player_name return "Could not find an album matching: " + genre.lower() elif artist: artists = device.get_album_artists(max_items=1000) for item in artists: if item.title.lower() == artist.lower(): sonos.play_library_item(device, state, item, play_mode="SHUFFLE", random_start=True) return "Playing music by " + item.title + " in " + device.player_name return "Could not find an artist matching: " + arists.lower() else: raise Exception("Must provide radio or genre")
def ungroup(self, room): device = sonos.get_speaker(room) device.unjoin() return device.player_name + " removed from group"
def pause(self, room): device = sonos.get_speaker(room) device.pause() return "Playback paused in " + device.player_name
def resume(self, room): device = sonos.get_speaker(room) device.play() return "Playback resumed in " + device.player_name