Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow for Honeywell Lyric."""
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
13 
14 
16  config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=DOMAIN
17 ):
18  """Config flow to handle Honeywell Lyric 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  async def async_step_reauth(
28  self, entry_data: Mapping[str, Any]
29  ) -> ConfigFlowResult:
30  """Perform reauth upon an API authentication error."""
31  return await self.async_step_reauth_confirmasync_step_reauth_confirm()
32 
34  self, user_input: dict[str, Any] | None = None
35  ) -> ConfigFlowResult:
36  """Dialog that informs the user that reauth is required."""
37  if user_input is None:
38  return self.async_show_form(step_id="reauth_confirm")
39  return await self.async_step_user()
40 
41  async def async_oauth_create_entry(self, data: dict[str, Any]) -> ConfigFlowResult:
42  """Create an oauth config entry or update existing entry for reauth."""
43  existing_entry = await self.async_set_unique_id(DOMAIN)
44  if existing_entry:
45  self.hass.config_entries.async_update_entry(existing_entry, data=data)
46  await self.hass.config_entries.async_reload(existing_entry.entry_id)
47  return self.async_abort(reason="reauth_successful")
48  return self.async_create_entry(title="Lyric", data=data)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
Definition: config_flow.py:29
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
Definition: config_flow.py:35
ConfigFlowResult async_oauth_create_entry(self, dict[str, Any] data)
Definition: config_flow.py:41