From 06626af337fbb5f3974238ef505edc43bec8084a Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 2 Dec 2020 14:55:47 +0100 Subject: [PATCH] Guard for when refreshing token fails (#43855) --- homeassistant/components/spotify/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/spotify/__init__.py b/homeassistant/components/spotify/__init__.py index 10fe70c611e..e28e1fcf315 100644 --- a/homeassistant/components/spotify/__init__.py +++ b/homeassistant/components/spotify/__init__.py @@ -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) - await session.async_ensure_token_valid() + + try: + await session.async_ensure_token_valid() + except aiohttp.ClientError as err: + raise ConfigEntryNotReady from err + spotify = Spotify(auth=session.token["access_token"]) try: