diff --git a/homeassistant/components/media_player/squeezebox.py b/homeassistant/components/media_player/squeezebox.py index 2f8c214fe3a..62b82048eb1 100644 --- a/homeassistant/components/media_player/squeezebox.py +++ b/homeassistant/components/media_player/squeezebox.py @@ -11,6 +11,7 @@ import urllib.parse import voluptuous as vol from homeassistant.components.media_player import ( + ATTR_MEDIA_ENQUEUE, SUPPORT_PLAY_MEDIA, MEDIA_TYPE_MUSIC, SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, PLATFORM_SCHEMA, SUPPORT_PREVIOUS_TRACK, SUPPORT_SEEK, SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET, MediaPlayerDevice) @@ -27,7 +28,7 @@ KNOWN_DEVICES = [] SUPPORT_SQUEEZEBOX = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | \ SUPPORT_VOLUME_MUTE | SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | \ - SUPPORT_SEEK | SUPPORT_TURN_ON | SUPPORT_TURN_OFF + SUPPORT_SEEK | SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_PLAY_MEDIA PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, @@ -303,3 +304,64 @@ class SqueezeBoxDevice(MediaPlayerDevice): """Turn the media player on.""" self._lms.query(self._id, 'power', '1') self.update_ha_state() + + def play_media(self, media_type, media_id, **kwargs): + """ + Send the play_media command to the media player. + + If ATTR_MEDIA_ENQUEUE is True, add `media_id` to the current playlist. + """ + if kwargs.get(ATTR_MEDIA_ENQUEUE): + self._add_uri_to_playlist(media_id) + else: + self._play_uri(media_id) + + def _play_uri(self, media_id): + """ + Replace the current play list with the uri. + + Telnet Command Strucutre: + playlist play <fadeInSecs> + + The "playlist play" command puts the specified song URL, + playlist or directory contents into the current playlist + and plays starting at the first item. Any songs previously + in the playlist are discarded. An optional title value may be + passed to set a title. This can be useful for remote URLs. + The "fadeInSecs" parameter may be passed to specify fade-in period. + + Examples: + Request: "04:20:00:12:23:45 playlist play + /music/abba/01_Voulez_Vous.mp3<LF>" + Response: "04:20:00:12:23:45 playlist play + /music/abba/01_Voulez_Vous.mp3<LF>" + + """ + self._lms.query(self._id, 'playlist', 'play', media_id) + self.update_ha_state() + + def _add_uri_to_playlist(self, media_id): + """ + Add a items to the existing playlist. + + Telnet Command Strucutre: + <playerid> playlist add <item> + + The "playlist add" command adds the specified song URL, playlist or + directory contents to the end of the current playlist. Songs + currently playing or already on the playlist are not affected. + + Examples: + Request: "04:20:00:12:23:45 playlist add + /music/abba/01_Voulez_Vous.mp3<LF>" + Response: "04:20:00:12:23:45 playlist add + /music/abba/01_Voulez_Vous.mp3<LF>" + + Request: "04:20:00:12:23:45 playlist add + /playlists/abba.m3u<LF>" + Response: "04:20:00:12:23:45 playlist add + /playlists/abba.m3u<LF>" + + """ + self._lms.query(self._id, 'playlist', 'add', media_id) + self.update_ha_state()