1 """Config flow to configure Renault component."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from renault_api.const
import AVAILABLE_LOCALES
10 from renault_api.gigya.exceptions
import GigyaException
11 import voluptuous
as vol
16 from .const
import CONF_KAMEREON_ACCOUNT_ID, CONF_LOCALE, DOMAIN
17 from .renault_hub
import RenaultHub
19 USER_SCHEMA = vol.Schema(
21 vol.Required(CONF_LOCALE): vol.In(AVAILABLE_LOCALES.keys()),
22 vol.Required(CONF_USERNAME): str,
23 vol.Required(CONF_PASSWORD): str,
26 REAUTH_SCHEMA = vol.Schema({vol.Required(CONF_PASSWORD): str})
30 """Handle a Renault config flow."""
32 renault_hub: RenaultHub
35 """Initialize the Renault config flow."""
36 self.renault_config: dict[str, Any] = {}
39 self, user_input: dict[str, Any] |
None =
None
40 ) -> ConfigFlowResult:
41 """Handle a Renault config flow start.
43 Ask the user for API keys.
45 errors: dict[str, str] = {}
47 locale = user_input[CONF_LOCALE]
48 self.renault_config.
update(user_input)
49 self.renault_config.
update(AVAILABLE_LOCALES[locale])
52 login_success = await self.
renault_hubrenault_hub.attempt_login(
53 user_input[CONF_USERNAME], user_input[CONF_PASSWORD]
55 except (aiohttp.ClientConnectionError, GigyaException):
56 errors[
"base"] =
"cannot_connect"
58 errors[
"base"] =
"unknown"
62 errors[
"base"] =
"invalid_credentials"
65 data_schema=USER_SCHEMA,
70 self, user_input: dict[str, Any] |
None =
None
71 ) -> ConfigFlowResult:
72 """Select Kamereon account."""
77 self.renault_config.
update(user_input)
79 title=user_input[CONF_KAMEREON_ACCOUNT_ID], data=self.renault_config
82 accounts = await self.
renault_hubrenault_hub.get_account_ids()
83 if len(accounts) == 0:
85 if len(accounts) == 1:
87 user_input={CONF_KAMEREON_ACCOUNT_ID: accounts[0]}
92 data_schema=vol.Schema(
93 {vol.Required(CONF_KAMEREON_ACCOUNT_ID): vol.In(accounts)}
98 self, entry_data: Mapping[str, Any]
99 ) -> ConfigFlowResult:
100 """Perform reauth upon an API authentication error."""
104 self, user_input: dict[str, Any] |
None =
None
105 ) -> ConfigFlowResult:
106 """Dialog that informs the user that reauth is required."""
107 errors: dict[str, str] = {}
112 if await self.
renault_hubrenault_hub.attempt_login(
113 reauth_entry.data[CONF_USERNAME], user_input[CONF_PASSWORD]
117 data_updates={CONF_PASSWORD: user_input[CONF_PASSWORD]},
119 errors = {
"base":
"invalid_credentials"}
122 step_id=
"reauth_confirm",
123 data_schema=REAUTH_SCHEMA,
125 description_placeholders={CONF_USERNAME: reauth_entry.data[CONF_USERNAME]},
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_kamereon(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry _get_reauth_entry(self)
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_abort(self, *str reason, 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)
_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)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
IssData update(pyiss.ISS iss)