From a482c4b2a119e100483940bdfb32742dd9befe1d Mon Sep 17 00:00:00 2001 From: Dan Cinnamon Date: Sun, 17 Apr 2016 14:34:33 -0500 Subject: [PATCH] Allow mpd to handle the play_media service. (#1831) Even though there's not really a place in the UI for it, it will now be possible to set a playlist as part of a script, and ultimately a scene. --- homeassistant/components/media_player/mpd.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/media_player/mpd.py b/homeassistant/components/media_player/mpd.py index 7ef78d7a028..266203e52e7 100644 --- a/homeassistant/components/media_player/mpd.py +++ b/homeassistant/components/media_player/mpd.py @@ -10,14 +10,16 @@ import socket from homeassistant.components.media_player import ( MEDIA_TYPE_MUSIC, SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PREVIOUS_TRACK, SUPPORT_TURN_OFF, SUPPORT_TURN_ON, - SUPPORT_VOLUME_SET, MediaPlayerDevice) + SUPPORT_VOLUME_SET, SUPPORT_PLAY_MEDIA, MEDIA_TYPE_PLAYLIST, + MediaPlayerDevice) from homeassistant.const import STATE_OFF, STATE_PAUSED, STATE_PLAYING _LOGGER = logging.getLogger(__name__) REQUIREMENTS = ['python-mpd2==0.5.5'] SUPPORT_MPD = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_TURN_OFF | \ - SUPPORT_TURN_ON | SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK + SUPPORT_TURN_ON | SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | \ + SUPPORT_PLAY_MEDIA # pylint: disable=unused-argument @@ -64,7 +66,7 @@ class MpdDevice(MediaPlayerDevice): """Representation of a MPD server.""" # MPD confuses pylint - # pylint: disable=no-member, abstract-method + # pylint: disable=no-member, too-many-public-methods, abstract-method def __init__(self, server, port, location, password): """Initialize the MPD device.""" import mpd @@ -203,3 +205,14 @@ class MpdDevice(MediaPlayerDevice): def media_previous_track(self): """Service to send the MPD the command for previous track.""" self.client.previous() + + def play_media(self, media_type, media_id): + """Send the media player the command for playing a playlist.""" + _LOGGER.info(str.format("Playing playlist: {0}", media_id)) + if media_type == MEDIA_TYPE_PLAYLIST: + self.client.clear() + self.client.load(media_id) + self.client.play() + else: + _LOGGER.error(str.format("Invalid media type. Expected: {0}", + MEDIA_TYPE_PLAYLIST))