Skip to content

Commit

Permalink
Add shuffle support for itunes component (#24319)
Browse files Browse the repository at this point in the history
* added shuffle support for itunes component

* fixed pylint errors

* more pylint

* final pylint (have my own dev env now)
  • Loading branch information
kvanhoorn authored and andrewsayre committed Jun 8, 2019
1 parent 5a9db70 commit 952d72f
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions homeassistant/components/itunes/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
MEDIA_TYPE_MUSIC, MEDIA_TYPE_PLAYLIST, SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE, SUPPORT_PLAY, SUPPORT_PLAY_MEDIA, SUPPORT_PREVIOUS_TRACK,
SUPPORT_SEEK, SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_VOLUME_MUTE,
SUPPORT_VOLUME_SET)
SUPPORT_VOLUME_SET, SUPPORT_SHUFFLE_SET)
from homeassistant.const import (
CONF_HOST, CONF_NAME, CONF_PORT, CONF_SSL, STATE_IDLE, STATE_OFF, STATE_ON,
STATE_PAUSED, STATE_PLAYING)
Expand All @@ -26,7 +26,7 @@

SUPPORT_ITUNES = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | SUPPORT_SEEK | \
SUPPORT_PLAY_MEDIA | SUPPORT_PLAY | SUPPORT_TURN_OFF
SUPPORT_PLAY_MEDIA | SUPPORT_PLAY | SUPPORT_TURN_OFF | SUPPORT_SHUFFLE_SET

SUPPORT_AIRPLAY = SUPPORT_VOLUME_SET | SUPPORT_TURN_ON | SUPPORT_TURN_OFF

Expand Down Expand Up @@ -96,6 +96,11 @@ def set_muted(self, muted):
"""Mute and returns the current state, muted True or False."""
return self._request('PUT', '/mute', {'muted': muted})

def set_shuffle(self, shuffle):
"""Set the shuffle mode, shuffle True or False."""
return self._request('PUT', '/shuffle',
{'mode': ('songs' if shuffle else 'off')})

def play(self):
"""Set playback to play and returns the current state."""
return self._command('play')
Expand Down Expand Up @@ -183,6 +188,7 @@ def __init__(self, name, host, port, use_ssl, add_entities):

self.current_volume = None
self.muted = None
self.shuffled = None
self.current_title = None
self.current_album = None
self.current_artist = None
Expand All @@ -207,6 +213,9 @@ def update_state(self, state_hash):
self.current_playlist = state_hash.get('playlist', None)
self.content_id = state_hash.get('id', None)

_shuffle = state_hash.get('shuffle', None)
self.shuffled = (_shuffle == 'songs')

@property
def name(self):
"""Return the name of the device."""
Expand Down Expand Up @@ -306,6 +315,11 @@ def media_playlist(self):
"""Title of the currently playing playlist."""
return self.current_playlist

@property
def shuffle(self):
"""Boolean if shuffle is enabled."""
return self.shuffled

@property
def supported_features(self):
"""Flag media player features that are supported."""
Expand All @@ -321,6 +335,11 @@ def mute_volume(self, mute):
response = self.client.set_muted(mute)
self.update_state(response)

def set_shuffle(self, shuffle):
"""Shuffle (true) or no shuffle (false) media player."""
response = self.client.set_shuffle(shuffle)
self.update_state(response)

def media_play(self):
"""Send media_play command to media player."""
response = self.client.play()
Expand Down

0 comments on commit 952d72f

Please sign in to comment.