1 """Config flow for Suez Water integration."""
3 from __future__
import annotations
8 from pysuez
import PySuezError, SuezClient
9 import voluptuous
as vol
15 from .const
import CONF_COUNTER_ID, DOMAIN
17 _LOGGER = logging.getLogger(__name__)
19 STEP_USER_DATA_SCHEMA = vol.Schema(
21 vol.Required(CONF_USERNAME): str,
22 vol.Required(CONF_PASSWORD): str,
23 vol.Optional(CONF_COUNTER_ID): str,
29 """Validate the user input allows us to connect.
31 Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
34 counter_id = data.get(CONF_COUNTER_ID)
40 if not await client.check_credentials():
42 except PySuezError
as ex:
43 raise CannotConnect
from ex
45 if counter_id
is None:
47 data[CONF_COUNTER_ID] = await client.find_counter()
48 except PySuezError
as ex:
49 raise CounterNotFound
from ex
53 """Handle a config flow for Suez Water."""
58 self, user_input: dict[str, Any] |
None =
None
59 ) -> ConfigFlowResult:
60 """Handle the initial step."""
61 errors: dict[str, str] = {}
62 if user_input
is not None:
68 errors[
"base"] =
"cannot_connect"
70 errors[
"base"] =
"invalid_auth"
71 except CounterNotFound:
72 errors[
"base"] =
"counter_not_found"
74 _LOGGER.exception(
"Unexpected exception")
75 errors[
"base"] =
"unknown"
78 title=user_input[CONF_USERNAME], data=user_input
82 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
87 """Error to indicate we cannot connect."""
91 """Error to indicate there is invalid auth."""
95 """Error to indicate we cannot automatically found the counter id."""
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|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_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)
None validate_input(dict[str, Any] data)