Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow for Minut Point."""
2 
3 from collections.abc import Mapping
4 import logging
5 from typing import Any
6 
7 from homeassistant.components.webhook import async_generate_id
8 from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlowResult
9 from homeassistant.const import CONF_TOKEN, CONF_WEBHOOK_ID
10 from homeassistant.helpers.config_entry_oauth2_flow import AbstractOAuth2FlowHandler
11 
12 from .const import DOMAIN
13 
14 
16  """Config flow to handle Minut Point 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  async def async_step_import(self, data: dict[str, Any]) -> ConfigFlowResult:
26  """Handle import from YAML."""
27  return await self.async_step_userasync_step_userasync_step_user()
28 
29  async def async_step_reauth(
30  self, entry_data: Mapping[str, Any]
31  ) -> ConfigFlowResult:
32  """Perform reauth upon an API authentication error."""
33  return await self.async_step_reauth_confirmasync_step_reauth_confirm()
34 
36  self, user_input: dict[str, Any] | None = None
37  ) -> ConfigFlowResult:
38  """Dialog that informs the user that reauth is required."""
39  if user_input is None:
40  return self.async_show_formasync_show_formasync_show_form(step_id="reauth_confirm")
41  return await self.async_step_userasync_step_userasync_step_user()
42 
43  async def async_oauth_create_entry(self, data: dict[str, Any]) -> ConfigFlowResult:
44  """Create an oauth config entry or update existing entry for reauth."""
45  user_id = str(data[CONF_TOKEN]["user_id"])
46  await self.async_set_unique_idasync_set_unique_id(user_id)
47  if self.sourcesourcesource != SOURCE_REAUTH:
48  self._abort_if_unique_id_configured_abort_if_unique_id_configured()
49 
50  return self.async_create_entryasync_create_entryasync_create_entry(
51  title="Minut Point",
52  data={**data, CONF_WEBHOOK_ID: async_generate_id()},
53  )
54 
55  reauth_entry = self._get_reauth_entry_get_reauth_entry()
56  if reauth_entry.unique_id is not None:
57  self._abort_if_unique_id_mismatch_abort_if_unique_id_mismatch(reason="wrong_account")
58 
59  logging.debug("user_id: %s", user_id)
60  return self.async_update_reload_and_abortasync_update_reload_and_abort(
61  reauth_entry, data_updates=data, unique_id=user_id
62  )
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
Definition: config_flow.py:37
ConfigFlowResult async_step_import(self, dict[str, Any] data)
Definition: config_flow.py:25
ConfigFlowResult async_oauth_create_entry(self, dict[str, Any] data)
Definition: config_flow.py:43
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
Definition: config_flow.py:31
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry|None async_set_unique_id(self, str|None unique_id=None, *bool raise_on_progress=True)
ConfigFlowResult async_create_entry(self, *str title, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None, Mapping[str, Any]|None options=None)
ConfigFlowResult async_update_reload_and_abort(self, ConfigEntry entry, *str|None|UndefinedType unique_id=UNDEFINED, str|UndefinedType title=UNDEFINED, Mapping[str, Any]|UndefinedType data=UNDEFINED, Mapping[str, Any]|UndefinedType data_updates=UNDEFINED, Mapping[str, Any]|UndefinedType options=UNDEFINED, str|UndefinedType reason=UNDEFINED, bool reload_even_if_entry_is_unchanged=True)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
None _abort_if_unique_id_mismatch(self, *str reason="unique_id_mismatch", Mapping[str, str]|None description_placeholders=None)
ConfigFlowResult async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
str
_FlowResultT async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_create_entry(self, *str|None title=None, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None)
str|None source(self)
config_entries.ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)