mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix Spotify session token refresh (#66386)
This commit is contained in:
parent
840d33f271
commit
ba83648d27
@ -107,6 +107,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
raise ConfigEntryNotReady
|
raise ConfigEntryNotReady
|
||||||
|
|
||||||
async def _update_devices() -> list[dict[str, Any]]:
|
async def _update_devices() -> list[dict[str, Any]]:
|
||||||
|
if not session.valid_token:
|
||||||
|
await session.async_ensure_token_valid()
|
||||||
|
await hass.async_add_executor_job(
|
||||||
|
spotify.set_auth, session.token["access_token"]
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
devices: dict[str, Any] | None = await hass.async_add_executor_job(
|
devices: dict[str, Any] | None = await hass.async_add_executor_job(
|
||||||
spotify.devices
|
spotify.devices
|
||||||
|
@ -172,7 +172,11 @@ async def async_browse_media_internal(
|
|||||||
partial(library_payload, can_play_artist=can_play_artist)
|
partial(library_payload, can_play_artist=can_play_artist)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not session.valid_token:
|
||||||
await session.async_ensure_token_valid()
|
await session.async_ensure_token_valid()
|
||||||
|
await hass.async_add_executor_job(
|
||||||
|
spotify.set_auth, session.token["access_token"]
|
||||||
|
)
|
||||||
|
|
||||||
# Strip prefix
|
# Strip prefix
|
||||||
if media_content_type:
|
if media_content_type:
|
||||||
|
@ -7,7 +7,7 @@ from datetime import timedelta
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from spotipy import Spotify, SpotifyException
|
from spotipy import SpotifyException
|
||||||
from yarl import URL
|
from yarl import URL
|
||||||
|
|
||||||
from homeassistant.components.media_player import BrowseMedia, MediaPlayerEntity
|
from homeassistant.components.media_player import BrowseMedia, MediaPlayerEntity
|
||||||
@ -367,7 +367,7 @@ class SpotifyMediaPlayer(MediaPlayerEntity):
|
|||||||
run_coroutine_threadsafe(
|
run_coroutine_threadsafe(
|
||||||
self.data.session.async_ensure_token_valid(), self.hass.loop
|
self.data.session.async_ensure_token_valid(), self.hass.loop
|
||||||
).result()
|
).result()
|
||||||
self.data.client = Spotify(auth=self.data.session.token["access_token"])
|
self.data.client.set_auth(auth=self.data.session.token["access_token"])
|
||||||
|
|
||||||
current = self.data.client.current_playback()
|
current = self.data.client.current_playback()
|
||||||
self._currently_playing = current or {}
|
self._currently_playing = current or {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user