1 """Config flow for Meater."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from meater
import AuthenticationError, MeaterApi, ServiceUnavailableError
9 import voluptuous
as vol
15 from .const
import DOMAIN
17 REAUTH_SCHEMA = vol.Schema({vol.Required(CONF_PASSWORD): str})
18 USER_SCHEMA = vol.Schema(
19 {vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
24 """Meater Config Flow."""
26 _data_schema = USER_SCHEMA
30 self, user_input: dict[str, str] |
None =
None
31 ) -> ConfigFlowResult:
32 """Define the login user step."""
33 if user_input
is None:
39 username: str = user_input[CONF_USERNAME]
43 username = user_input[CONF_USERNAME]
44 password = user_input[CONF_PASSWORD]
49 self, entry_data: Mapping[str, Any]
50 ) -> ConfigFlowResult:
51 """Handle configuration by re-auth."""
57 self, user_input: dict[str, str] |
None =
None
58 ) -> ConfigFlowResult:
59 """Handle re-auth completion."""
60 placeholders = {
"username": self.
_username_username}
63 step_id=
"reauth_confirm",
65 description_placeholders=placeholders,
68 password = user_input[CONF_PASSWORD]
70 "reauth_confirm", placeholders, self.
_username_username, password
74 self, step_id, placeholders: dict[str, str] |
None, username: str, password: str
75 ) -> ConfigFlowResult:
76 session = aiohttp_client.async_get_clientsession(self.hass)
78 api = MeaterApi(session)
82 await api.authenticate(username, password)
83 except AuthenticationError:
84 errors[
"base"] =
"invalid_auth"
85 except ServiceUnavailableError:
86 errors[
"base"] =
"service_unavailable_error"
88 errors[
"base"] =
"unknown_auth_error"
90 data = {
"username": username,
"password": password}
93 self.hass.config_entries.async_update_entry(existing_entry, data=data)
94 await self.hass.config_entries.async_reload(existing_entry.entry_id)
104 description_placeholders=placeholders,
ConfigFlowResult async_step_user(self, dict[str, str]|None user_input=None)
ConfigFlowResult _try_connect_meater(self, step_id, dict[str, str]|None placeholders, str username, str password)
ConfigFlowResult async_step_reauth_confirm(self, dict[str, str]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
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_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)