1 """Config flow for Open Exchange Rates integration."""
3 from __future__
import annotations
6 from collections.abc
import Mapping
9 from aioopenexchangerates
import (
11 OpenExchangeRatesAuthError,
12 OpenExchangeRatesClientError,
14 import voluptuous
as vol
22 from .const
import CLIENT_TIMEOUT, DEFAULT_BASE, DOMAIN, LOGGER
26 currencies: dict[str, str], existing_data: Mapping[str, str]
28 """Return a form schema."""
31 vol.Required(CONF_API_KEY): str,
33 CONF_BASE, default=existing_data.get(CONF_BASE)
or DEFAULT_BASE
34 ): vol.In(currencies),
39 async
def validate_input(hass: HomeAssistant, data: dict[str, str]) -> dict[str, str]:
40 """Validate the user input allows us to connect."""
43 async
with asyncio.timeout(CLIENT_TIMEOUT):
44 await client.get_latest(base=data[CONF_BASE])
46 return {
"title": data[CONF_BASE]}
50 """Handle a config flow for Open Exchange Rates."""
55 """Initialize the config flow."""
59 self, user_input: dict[str, Any] |
None =
None
60 ) -> ConfigFlowResult:
61 """Handle the initial step."""
64 if user_input
is None:
65 existing_data: Mapping[str, Any] = {}
71 description_placeholders={
72 "signup":
"https://openexchangerates.org/signup"
80 except OpenExchangeRatesAuthError:
81 errors[
"base"] =
"invalid_auth"
82 except OpenExchangeRatesClientError:
83 errors[
"base"] =
"cannot_connect"
85 errors[
"base"] =
"timeout_connect"
87 LOGGER.exception(
"Unexpected exception")
88 errors[
"base"] =
"unknown"
92 CONF_API_KEY: user_input[CONF_API_KEY],
93 CONF_BASE: user_input[CONF_BASE],
107 description_placeholders={
"signup":
"https://openexchangerates.org/signup"},
112 self, entry_data: Mapping[str, Any]
113 ) -> ConfigFlowResult:
118 """Get the available currencies."""
122 async
with asyncio.timeout(CLIENT_TIMEOUT):
124 except OpenExchangeRatesClientError
as err:
125 raise AbortFlow(
"cannot_connect")
from err
126 except TimeoutError
as err:
127 raise AbortFlow(
"timeout_connect")
from err
dict[str, str] async_get_currencies(self)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigEntry _get_reauth_entry(self)
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 _async_abort_entries_match(self, dict[str, Any]|None match_dict=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)
_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)
dict[str, str] validate_input(HomeAssistant hass, dict[str, str] data)
vol.Schema get_data_schema(dict[str, str] currencies, Mapping[str, str] existing_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)