Add repeat mode support to Spotify (#43247)

pull/43473/head
Franck Nijhof 2020-11-21 11:38:40 +01:00 committed by GitHub
parent 7c6e80952b
commit db0dee1ab2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 0 deletions

View File

@ -25,12 +25,16 @@ from homeassistant.components.media_player.const import (
MEDIA_TYPE_MUSIC,
MEDIA_TYPE_PLAYLIST,
MEDIA_TYPE_TRACK,
REPEAT_MODE_ALL,
REPEAT_MODE_OFF,
REPEAT_MODE_ONE,
SUPPORT_BROWSE_MEDIA,
SUPPORT_NEXT_TRACK,
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_PLAY_MEDIA,
SUPPORT_PREVIOUS_TRACK,
SUPPORT_REPEAT_SET,
SUPPORT_SEEK,
SUPPORT_SELECT_SOURCE,
SUPPORT_SHUFFLE_SET,
@ -71,12 +75,19 @@ SUPPORT_SPOTIFY = (
| SUPPORT_PLAY
| SUPPORT_PLAY_MEDIA
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_REPEAT_SET
| SUPPORT_SEEK
| SUPPORT_SELECT_SOURCE
| SUPPORT_SHUFFLE_SET
| SUPPORT_VOLUME_SET
)
REPEAT_MODE_MAPPING = {
"context": REPEAT_MODE_ALL,
"off": REPEAT_MODE_OFF,
"track": REPEAT_MODE_ONE,
}
BROWSE_LIMIT = 48
MEDIA_TYPE_SHOW = "show"
@ -375,6 +386,12 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
"""Shuffling state."""
return bool(self._currently_playing.get("shuffle_state"))
@property
def repeat(self) -> Optional[str]:
"""Return current repeat mode."""
repeat_state = self._currently_playing.get("repeat_state")
return REPEAT_MODE_MAPPING.get(repeat_state)
@property
def supported_features(self) -> int:
"""Return the media player features that are supported."""
@ -449,6 +466,13 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
"""Enable/Disable shuffle mode."""
self._spotify.shuffle(shuffle)
@spotify_exception_handler
def set_repeat(self, repeat: str) -> None:
"""Set repeat mode."""
for spotify, home_assistant in REPEAT_MODE_MAPPING.items():
if home_assistant == repeat:
self._spotify.repeat(spotify)
@spotify_exception_handler
def update(self) -> None:
"""Update state and attributes."""