mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Merge pull request #488 from balloob/itunes-play-media
iTunes play_media
This commit is contained in:
commit
e0149c4ee4
@ -35,9 +35,10 @@ URL of your running version of iTunes-API. Example: http://192.168.1.50:8181
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
MediaPlayerDevice, MEDIA_TYPE_MUSIC, SUPPORT_PAUSE, SUPPORT_SEEK,
|
MediaPlayerDevice, MEDIA_TYPE_MUSIC, MEDIA_TYPE_PLAYLIST, SUPPORT_PAUSE,
|
||||||
SUPPORT_VOLUME_SET, SUPPORT_VOLUME_MUTE, SUPPORT_PREVIOUS_TRACK,
|
SUPPORT_SEEK, SUPPORT_VOLUME_SET, SUPPORT_VOLUME_MUTE,
|
||||||
SUPPORT_NEXT_TRACK, SUPPORT_TURN_ON, SUPPORT_TURN_OFF,
|
SUPPORT_PREVIOUS_TRACK, SUPPORT_NEXT_TRACK, SUPPORT_TURN_ON,
|
||||||
|
SUPPORT_TURN_OFF, SUPPORT_PLAY_MEDIA,
|
||||||
ATTR_ENTITY_PICTURE, ATTR_SUPPORTED_MEDIA_COMMANDS)
|
ATTR_ENTITY_PICTURE, ATTR_SUPPORTED_MEDIA_COMMANDS)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_IDLE, STATE_PLAYING, STATE_PAUSED, STATE_OFF, STATE_ON)
|
STATE_IDLE, STATE_PLAYING, STATE_PAUSED, STATE_OFF, STATE_ON)
|
||||||
@ -47,7 +48,8 @@ import requests
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SUPPORT_ITUNES = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
SUPPORT_ITUNES = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
||||||
SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | SUPPORT_SEEK
|
SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | SUPPORT_SEEK | \
|
||||||
|
SUPPORT_PLAY_MEDIA
|
||||||
|
|
||||||
SUPPORT_AIRPLAY = SUPPORT_VOLUME_SET | SUPPORT_TURN_ON | SUPPORT_TURN_OFF
|
SUPPORT_AIRPLAY = SUPPORT_VOLUME_SET | SUPPORT_TURN_ON | SUPPORT_TURN_OFF
|
||||||
|
|
||||||
@ -118,6 +120,20 @@ class Itunes(object):
|
|||||||
""" Skips back and returns the current state. """
|
""" Skips back and returns the current state. """
|
||||||
return self._command('previous')
|
return self._command('previous')
|
||||||
|
|
||||||
|
def play_playlist(self, playlist_id_or_name):
|
||||||
|
""" Sets a playlist to be current and returns the current state. """
|
||||||
|
response = self._request('GET', '/playlists')
|
||||||
|
playlists = response.get('playlists', [])
|
||||||
|
|
||||||
|
found_playlists = \
|
||||||
|
[playlist for playlist in playlists if
|
||||||
|
(playlist_id_or_name in [playlist["name"], playlist["id"]])]
|
||||||
|
|
||||||
|
if len(found_playlists) > 0:
|
||||||
|
playlist = found_playlists[0]
|
||||||
|
path = '/playlists/' + playlist['id'] + '/play'
|
||||||
|
return self._request('PUT', path)
|
||||||
|
|
||||||
def artwork_url(self):
|
def artwork_url(self):
|
||||||
""" Returns a URL of the current track's album art. """
|
""" Returns a URL of the current track's album art. """
|
||||||
return self._base_url + '/artwork'
|
return self._base_url + '/artwork'
|
||||||
@ -294,6 +310,11 @@ class ItunesDevice(MediaPlayerDevice):
|
|||||||
""" Album of current playing media. (Music track only) """
|
""" Album of current playing media. (Music track only) """
|
||||||
return self.current_album
|
return self.current_album
|
||||||
|
|
||||||
|
@property
|
||||||
|
def media_playlist(self):
|
||||||
|
""" Title of the currently playing playlist. """
|
||||||
|
return self.current_playlist
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_media_commands(self):
|
def supported_media_commands(self):
|
||||||
""" Flags of media commands that are supported. """
|
""" Flags of media commands that are supported. """
|
||||||
@ -329,6 +350,12 @@ class ItunesDevice(MediaPlayerDevice):
|
|||||||
response = self.client.previous()
|
response = self.client.previous()
|
||||||
self.update_state(response)
|
self.update_state(response)
|
||||||
|
|
||||||
|
def play_media(self, media_type, media_id):
|
||||||
|
""" play_media media player. """
|
||||||
|
if media_type == MEDIA_TYPE_PLAYLIST:
|
||||||
|
response = self.client.play_playlist(media_id)
|
||||||
|
self.update_state(response)
|
||||||
|
|
||||||
|
|
||||||
class AirPlayDevice(MediaPlayerDevice):
|
class AirPlayDevice(MediaPlayerDevice):
|
||||||
""" Represents an AirPlay device via an iTunes-API instance. """
|
""" Represents an AirPlay device via an iTunes-API instance. """
|
||||||
|
Loading…
x
Reference in New Issue
Block a user