Add support for restricted playback devices in Spotify (#96794)

* Add support for restricted devices

* Add support for restricted devices
This commit is contained in:
Joost Lekkerkerker 2023-07-18 11:15:41 +02:00 committed by GitHub
parent 772fb463b5
commit a69b5a8d3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -120,9 +120,6 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
self._attr_unique_id = user_id
if self.data.current_user["product"] == "premium":
self._attr_supported_features = SUPPORT_SPOTIFY
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, user_id)},
manufacturer="Spotify AB",
@ -137,6 +134,16 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
)
self._currently_playing: dict | None = {}
self._playlist: dict | None = None
self._restricted_device: bool = False
@property
def supported_features(self) -> MediaPlayerEntityFeature:
"""Return the supported features."""
if self._restricted_device:
return MediaPlayerEntityFeature.SELECT_SOURCE
if self.data.current_user["product"] == "premium":
return SUPPORT_SPOTIFY
return MediaPlayerEntityFeature(0)
@property
def state(self) -> MediaPlayerState:
@ -398,6 +405,9 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
self._playlist = None
if context["type"] == MediaType.PLAYLIST:
self._playlist = self.data.client.playlist(current["context"]["uri"])
device = self._currently_playing.get("device")
if device is not None:
self._restricted_device = device["is_restricted"]
async def async_browse_media(
self,