Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow for myUplink."""
2 
3 from collections.abc import Mapping
4 import logging
5 from typing import Any
6 
7 from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlowResult
8 from homeassistant.helpers import config_entry_oauth2_flow
9 
10 from .const import DOMAIN, OAUTH2_SCOPES
11 
12 
14  config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=DOMAIN
15 ):
16  """Config flow to handle myUplink OAuth2 authentication."""
17 
18  DOMAIN = DOMAIN
19 
20  @property
21  def logger(self) -> logging.Logger:
22  """Return logger."""
23  return logging.getLogger(__name__)
24 
25  @property
26  def extra_authorize_data(self) -> dict[str, Any]:
27  """Extra data that needs to be appended to the authorize url."""
28  return {"scope": " ".join(OAUTH2_SCOPES)}
29 
30  async def async_step_reauth(
31  self, entry_data: Mapping[str, Any]
32  ) -> ConfigFlowResult:
33  """Perform reauth upon an API authentication error."""
34  return await self.async_step_reauth_confirmasync_step_reauth_confirm()
35 
37  self, user_input: Mapping[str, Any] | None = None
38  ) -> ConfigFlowResult:
39  """Dialog that informs the user that reauth is required."""
40  if user_input is None:
41  return self.async_show_form(
42  step_id="reauth_confirm",
43  )
44 
45  return await self.async_step_user()
46 
47  async def async_oauth_create_entry(self, data: dict) -> ConfigFlowResult:
48  """Create or update the config entry."""
49  if self.sourcesource == SOURCE_REAUTH:
50  return self.async_update_reload_and_abort(
51  self._get_reauth_entry(), data=data
52  )
53  return await super().async_oauth_create_entry(data)