1 """Config flow for Spotify."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from spotifyaio
import SpotifyClient
16 from .const
import DOMAIN, SPOTIFY_SCOPES
20 config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=DOMAIN
22 """Config flow to handle Spotify OAuth2 authentication."""
30 return logging.getLogger(__name__)
34 """Extra data that needs to be appended to the authorize url."""
35 return {
"scope":
",".join(SPOTIFY_SCOPES)}
38 """Create an entry for Spotify."""
40 spotify.authenticate(data[CONF_TOKEN][CONF_ACCESS_TOKEN])
43 current_user = await spotify.get_current_user()
45 return self.async_abort(reason=
"connection_error")
47 name = current_user.display_name
49 await self.async_set_unique_id(current_user.user_id)
51 if self.
sourcesource == SOURCE_REAUTH:
52 self._abort_if_unique_id_mismatch(reason=
"reauth_account_mismatch")
53 return self.async_update_reload_and_abort(
54 self._get_reauth_entry(), title=name, data=data
56 return self.async_create_entry(title=name, data={**data, CONF_NAME: name})
59 self, entry_data: Mapping[str, Any]
60 ) -> ConfigFlowResult:
61 """Perform reauth upon migration of old entries."""
65 self, user_input: dict[str, Any] |
None =
None
66 ) -> ConfigFlowResult:
67 """Confirm reauth dialog."""
68 reauth_entry = self._get_reauth_entry()
69 if user_input
is None:
70 return self.async_show_form(
71 step_id=
"reauth_confirm",
72 description_placeholders={
"account": reauth_entry.data[
"id"]},
76 return await self.async_step_pick_implementation(
77 user_input={
"implementation": reauth_entry.data[
"auth_implementation"]}
ConfigFlowResult async_oauth_create_entry(self, dict[str, Any] data)
logging.Logger logger(self)
dict[str, Any] extra_authorize_data(self)
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)