mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Add support for the Spotify DJ (#107268)
* Add support for the Spotify DJ playlist by mocking the playlist response Add error handling for playlist lookup to ensure it doesn't break current playback state loading * Run linters Add exception type to playlist lookup error handling * Fix typo in comment Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
4af47a4815
commit
427f7a7866
@ -61,6 +61,10 @@ REPEAT_MODE_MAPPING_TO_SPOTIFY = {
|
|||||||
value: key for key, value in REPEAT_MODE_MAPPING_TO_HA.items()
|
value: key for key, value in REPEAT_MODE_MAPPING_TO_HA.items()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# This is a minimal representation of the DJ playlist that Spotify now offers
|
||||||
|
# The DJ is not fully integrated with the playlist API, so needs to have the playlist response mocked in order to maintain functionality
|
||||||
|
SPOTIFY_DJ_PLAYLIST = {"uri": "spotify:playlist:37i9dQZF1EYkqdzj48dyYq", "name": "DJ"}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -423,7 +427,19 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
|
|||||||
if context and (self._playlist is None or self._playlist["uri"] != uri):
|
if context and (self._playlist is None or self._playlist["uri"] != uri):
|
||||||
self._playlist = None
|
self._playlist = None
|
||||||
if context["type"] == MediaType.PLAYLIST:
|
if context["type"] == MediaType.PLAYLIST:
|
||||||
self._playlist = self.data.client.playlist(uri)
|
# The Spotify API does not currently support doing a lookup for the DJ playlist, so just use the minimal mock playlist object
|
||||||
|
if uri == SPOTIFY_DJ_PLAYLIST["uri"]:
|
||||||
|
self._playlist = SPOTIFY_DJ_PLAYLIST
|
||||||
|
else:
|
||||||
|
# Make sure any playlist lookups don't break the current playback state update
|
||||||
|
try:
|
||||||
|
self._playlist = self.data.client.playlist(uri)
|
||||||
|
except SpotifyException:
|
||||||
|
_LOGGER.debug(
|
||||||
|
"Unable to load spotify playlist '%s'. Continuing without playlist data",
|
||||||
|
uri,
|
||||||
|
)
|
||||||
|
self._playlist = None
|
||||||
|
|
||||||
device = self._currently_playing.get("device")
|
device = self._currently_playing.get("device")
|
||||||
if device is not None:
|
if device is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user