From 9b7ecddde6fd3d212ed5f5df4214d62f713659c0 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 5 Dec 2020 15:05:12 +0100 Subject: [PATCH] Add reverse repeatmode mapping constant to Spotify (#43968) --- homeassistant/components/spotify/media_player.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/spotify/media_player.py b/homeassistant/components/spotify/media_player.py index ef3f1224a4b..e4450e7a306 100644 --- a/homeassistant/components/spotify/media_player.py +++ b/homeassistant/components/spotify/media_player.py @@ -82,12 +82,16 @@ SUPPORT_SPOTIFY = ( | SUPPORT_VOLUME_SET ) -REPEAT_MODE_MAPPING = { +REPEAT_MODE_MAPPING_TO_HA = { "context": REPEAT_MODE_ALL, "off": REPEAT_MODE_OFF, "track": REPEAT_MODE_ONE, } +REPEAT_MODE_MAPPING_TO_SPOTIFY = { + value: key for key, value in REPEAT_MODE_MAPPING_TO_HA.items() +} + BROWSE_LIMIT = 48 MEDIA_TYPE_SHOW = "show" @@ -390,7 +394,7 @@ class SpotifyMediaPlayer(MediaPlayerEntity): def repeat(self) -> Optional[str]: """Return current repeat mode.""" repeat_state = self._currently_playing.get("repeat_state") - return REPEAT_MODE_MAPPING.get(repeat_state) + return REPEAT_MODE_MAPPING_TO_HA.get(repeat_state) @property def supported_features(self) -> int: @@ -469,9 +473,9 @@ class SpotifyMediaPlayer(MediaPlayerEntity): @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) + if repeat not in REPEAT_MODE_MAPPING_TO_SPOTIFY: + raise ValueError(f"Unsupported repeat mode: {repeat}") + self._spotify.repeat(REPEAT_MODE_MAPPING_TO_SPOTIFY[repeat]) @spotify_exception_handler def update(self) -> None: