1 """Config flow for OurGroceries integration."""
3 from __future__
import annotations
8 from aiohttp
import ClientError
9 from ourgroceries
import OurGroceries
10 from ourgroceries.exceptions
import InvalidLoginException
11 import voluptuous
as vol
16 from .const
import DOMAIN
18 _LOGGER = logging.getLogger(__name__)
20 STEP_USER_DATA_SCHEMA = vol.Schema(
22 vol.Required(CONF_USERNAME): str,
23 vol.Required(CONF_PASSWORD): str,
29 """Handle a config flow for OurGroceries."""
34 self, user_input: dict[str, Any] |
None =
None
35 ) -> ConfigFlowResult:
36 """Handle the initial step."""
37 errors: dict[str, str] = {}
38 if user_input
is not None:
39 og = OurGroceries(user_input[CONF_USERNAME], user_input[CONF_PASSWORD])
42 except (TimeoutError, ClientError):
43 errors[
"base"] =
"cannot_connect"
44 except InvalidLoginException:
45 errors[
"base"] =
"invalid_auth"
47 _LOGGER.exception(
"Unexpected exception")
48 errors[
"base"] =
"unknown"
51 title=user_input[CONF_USERNAME], data=user_input
55 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
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)
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)