mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Store new spotify client in hass.data (#64984)
This commit is contained in:
parent
9ff49e9c3a
commit
d14fbf40c8
@ -217,9 +217,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Spotify based on a config entry."""
|
"""Set up Spotify based on a config entry."""
|
||||||
spotify = SpotifyMediaPlayer(
|
spotify = SpotifyMediaPlayer(
|
||||||
hass.data[DOMAIN][entry.entry_id][DATA_SPOTIFY_SESSION],
|
hass.data[DOMAIN][entry.entry_id],
|
||||||
hass.data[DOMAIN][entry.entry_id][DATA_SPOTIFY_CLIENT],
|
|
||||||
hass.data[DOMAIN][entry.entry_id][DATA_SPOTIFY_ME],
|
|
||||||
entry.data[CONF_ID],
|
entry.data[CONF_ID],
|
||||||
entry.data[CONF_NAME],
|
entry.data[CONF_NAME],
|
||||||
)
|
)
|
||||||
@ -258,19 +256,15 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
session: OAuth2Session,
|
spotify_data,
|
||||||
spotify: Spotify,
|
|
||||||
me: dict, # pylint: disable=invalid-name
|
|
||||||
user_id: str,
|
user_id: str,
|
||||||
name: str,
|
name: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self._id = user_id
|
self._id = user_id
|
||||||
self._me = me
|
self._spotify_data = spotify_data
|
||||||
self._name = f"Spotify {name}"
|
self._name = f"Spotify {name}"
|
||||||
self._session = session
|
self._scope_ok = set(self._session.token["scope"].split(" ")).issuperset(
|
||||||
self._spotify = spotify
|
|
||||||
self._scope_ok = set(session.token["scope"].split(" ")).issuperset(
|
|
||||||
SPOTIFY_SCOPES
|
SPOTIFY_SCOPES
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -281,6 +275,21 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
|
|||||||
self._attr_name = self._name
|
self._attr_name = self._name
|
||||||
self._attr_unique_id = user_id
|
self._attr_unique_id = user_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _me(self) -> dict:
|
||||||
|
"""Return spotify user info."""
|
||||||
|
return self._spotify_data[DATA_SPOTIFY_ME]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _session(self) -> OAuth2Session:
|
||||||
|
"""Return spotify session."""
|
||||||
|
return self._spotify_data[DATA_SPOTIFY_SESSION]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _spotify(self) -> Spotify:
|
||||||
|
"""Return spotify API."""
|
||||||
|
return self._spotify_data[DATA_SPOTIFY_CLIENT]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self) -> DeviceInfo:
|
def device_info(self) -> DeviceInfo:
|
||||||
"""Return device information about this entity."""
|
"""Return device information about this entity."""
|
||||||
@ -501,7 +510,9 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
|
|||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self._session.async_ensure_token_valid(), self.hass.loop
|
self._session.async_ensure_token_valid(), self.hass.loop
|
||||||
).result()
|
).result()
|
||||||
self._spotify = Spotify(auth=self._session.token["access_token"])
|
self._spotify_data[DATA_SPOTIFY_CLIENT] = Spotify(
|
||||||
|
auth=self._session.token["access_token"]
|
||||||
|
)
|
||||||
|
|
||||||
current = self._spotify.current_playback()
|
current = self._spotify.current_playback()
|
||||||
self._currently_playing = current or {}
|
self._currently_playing = current or {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user