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