From d5912f41fb45bb5a43ff0e0d0dac726c34331806 Mon Sep 17 00:00:00 2001 From: Sytone Date: Fri, 23 Sep 2016 00:05:33 -0700 Subject: [PATCH] Added play media to squeezebox (#3306) * Added play media to squeezebox The squeezebox component can now add a URI to an existing playlist or just over write it to force a stream to play. * Cleaned up flake8 issues with formatting. Spacing... The end of the world! Fixed. Once day the tools will fix this on the fly, one day... [x] ./homeassistant/components/media_player/squeezebox.py:307:1: W293 blank line contains whitespace [x] ./homeassistant/components/media_player/squeezebox.py:366:1: W391 blank line at end of file [x] ./homeassistant/components/media_player/squeezebox.py:366:1: W293 blank line contains whitespace Updated SUPPORT_SQUEEZEBOX to add SUPPORT_PLAY_MEDIA [x] ./homeassistant/components/media_player/squeezebox.py:13:1: F401 'homeassistant.components.media_player.SUPPORT_PLAY_MEDIA' imported but unused * Updates from review Updated the comments to indicate they are developer / API comments and not for end users. Marked the private functions with a leading underscore (_) * Fixed Lint issues. 202ERROR: InvocationError: '/home/travis/build/home-assistant/home-assistant/.tox/lint/bin/flake8' 203lint runtests: commands[1] | pylint homeassistant 204************* Module homeassistant.components.media_player.squeezebox 205C:322, 0: Trailing whitespace (trailing-whitespace) --- .../components/media_player/squeezebox.py | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) 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()