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.pull/1892/head
parent
e8bf47ff59
commit
a482c4b2a1
|
@ -10,14 +10,16 @@ import socket
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
MEDIA_TYPE_MUSIC, SUPPORT_NEXT_TRACK, SUPPORT_PAUSE,
|
MEDIA_TYPE_MUSIC, SUPPORT_NEXT_TRACK, SUPPORT_PAUSE,
|
||||||
SUPPORT_PREVIOUS_TRACK, SUPPORT_TURN_OFF, SUPPORT_TURN_ON,
|
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
|
from homeassistant.const import STATE_OFF, STATE_PAUSED, STATE_PLAYING
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
REQUIREMENTS = ['python-mpd2==0.5.5']
|
REQUIREMENTS = ['python-mpd2==0.5.5']
|
||||||
|
|
||||||
SUPPORT_MPD = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_TURN_OFF | \
|
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
|
# pylint: disable=unused-argument
|
||||||
|
@ -64,7 +66,7 @@ class MpdDevice(MediaPlayerDevice):
|
||||||
"""Representation of a MPD server."""
|
"""Representation of a MPD server."""
|
||||||
|
|
||||||
# MPD confuses pylint
|
# 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):
|
def __init__(self, server, port, location, password):
|
||||||
"""Initialize the MPD device."""
|
"""Initialize the MPD device."""
|
||||||
import mpd
|
import mpd
|
||||||
|
@ -203,3 +205,14 @@ class MpdDevice(MediaPlayerDevice):
|
||||||
def media_previous_track(self):
|
def media_previous_track(self):
|
||||||
"""Service to send the MPD the command for previous track."""
|
"""Service to send the MPD the command for previous track."""
|
||||||
self.client.previous()
|
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))
|
||||||
|
|
Loading…
Reference in New Issue