1 """Config flow for SimpleFIN integration."""
5 from simplefin4py
import SimpleFin
6 from simplefin4py.exceptions
import (
9 SimpleFinInvalidAccountURLError,
10 SimpleFinInvalidClaimTokenError,
11 SimpleFinPaymentRequiredError,
13 import voluptuous
as vol
17 from .const
import CONF_ACCESS_URL, DOMAIN, LOGGER
21 """Handle a config flow for the initial setup of a SimpleFIN integration."""
24 self, user_input: dict[str, Any] |
None =
None
25 ) -> ConfigFlowResult:
26 """Prompt user for SimpleFIN API credentials."""
27 errors: dict[str, str] = {}
29 if user_input
is not None:
30 access_url: str = user_input[CONF_ACCESS_URL]
34 if not access_url.startswith(
"http"):
36 LOGGER.debug(
"[Setup Token] - Claiming Access URL")
37 access_url = await SimpleFin.claim_setup_token(access_url)
39 LOGGER.debug(
"[Access Url] - 'http' string detected")
41 LOGGER.debug(
"[Access Url] - validating access url")
42 SimpleFin.decode_access_url(access_url)
44 LOGGER.debug(
"[Access Url] - Fetching data")
45 simple_fin = SimpleFin(access_url=access_url)
46 await simple_fin.fetch_data()
48 except SimpleFinInvalidAccountURLError:
49 errors[
"base"] =
"url_error"
50 except SimpleFinInvalidClaimTokenError:
51 errors[
"base"] =
"invalid_claim_token"
52 except SimpleFinClaimError:
53 errors[
"base"] =
"claim_error"
54 except SimpleFinPaymentRequiredError:
55 errors[
"base"] =
"payment_required"
56 except SimpleFinAuthError:
57 errors[
"base"] =
"invalid_auth"
60 user_input[CONF_ACCESS_URL] = access_url
64 data={CONF_ACCESS_URL: user_input[CONF_ACCESS_URL]},
69 data_schema=vol.Schema(
71 vol.Required(CONF_ACCESS_URL): str,
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
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)
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)