Guard for when refreshing token fails (#43855)

This commit is contained in:
Paulus Schoutsen 2020-12-02 14:55:47 +01:00 committed by GitHub
parent 15b5057569
commit 06626af337
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
"""The spotify integration."""
import aiohttp
from spotipy import Spotify, SpotifyException
import voluptuous as vol
@ -62,7 +63,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Spotify from a config entry."""
implementation = await async_get_config_entry_implementation(hass, entry)
session = OAuth2Session(hass, entry, implementation)
try:
await session.async_ensure_token_valid()
except aiohttp.ClientError as err:
raise ConfigEntryNotReady from err
spotify = Spotify(auth=session.token["access_token"])
try: