1 """Config flow for Roborock."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
6 from copy
import deepcopy
10 from roborock.containers
import UserData
11 from roborock.exceptions
import (
12 RoborockAccountDoesNotExist,
16 RoborockTooFrequentCodeRequests,
19 from roborock.web_api
import RoborockApiClient
20 import voluptuous
as vol
41 _LOGGER = logging.getLogger(__name__)
45 """Handle a config flow for Roborock."""
50 """Initialize the config flow."""
51 self.
_username_username: str |
None =
None
52 self.
_client_client: RoborockApiClient |
None =
None
55 self, user_input: dict[str, Any] |
None =
None
56 ) -> ConfigFlowResult:
57 """Handle a flow initialized by the user."""
58 errors: dict[str, str] = {}
60 if user_input
is not None:
61 username = user_input[CONF_USERNAME]
65 _LOGGER.debug(
"Requesting code for Roborock account")
66 self.
_client_client = RoborockApiClient(username)
72 data_schema=vol.Schema({vol.Required(CONF_USERNAME): str}),
78 errors: dict[str, str] = {}
80 await self.
_client_client.request_code()
81 except RoborockAccountDoesNotExist:
82 errors[
"base"] =
"invalid_email"
83 except RoborockUrlException:
84 errors[
"base"] =
"unknown_url"
85 except RoborockInvalidEmail:
86 errors[
"base"] =
"invalid_email_format"
87 except RoborockTooFrequentCodeRequests:
88 errors[
"base"] =
"too_frequent_code_requests"
89 except RoborockException:
90 _LOGGER.exception(
"Unexpected exception")
91 errors[
"base"] =
"unknown_roborock"
93 _LOGGER.exception(
"Unexpected exception")
94 errors[
"base"] =
"unknown"
99 user_input: dict[str, Any] |
None =
None,
100 ) -> ConfigFlowResult:
101 """Handle a flow initialized by the user."""
102 errors: dict[str, str] = {}
105 if user_input
is not None:
106 code = user_input[CONF_ENTRY_CODE]
107 _LOGGER.debug(
"Logging into Roborock account using email provided code")
109 login_data = await self.
_client_client.code_login(code)
110 except RoborockInvalidCode:
111 errors[
"base"] =
"invalid_code"
112 except RoborockException:
113 _LOGGER.exception(
"Unexpected exception")
114 errors[
"base"] =
"unknown_roborock"
116 _LOGGER.exception(
"Unexpected exception")
117 errors[
"base"] =
"unknown"
121 self.hass.config_entries.async_update_entry(
125 CONF_USER_DATA: login_data.as_dict(),
133 data_schema=vol.Schema({vol.Required(CONF_ENTRY_CODE): str}),
138 self, entry_data: Mapping[str, Any]
139 ) -> ConfigFlowResult:
140 """Perform reauth upon an API authentication error."""
141 self.
_username_username = entry_data[CONF_USERNAME]
147 self, user_input: dict[str, Any] |
None =
None
148 ) -> ConfigFlowResult:
149 """Confirm reauth dialog."""
150 errors: dict[str, str] = {}
151 if user_input
is not None:
158 self, client: RoborockApiClient, username: str, user_data: UserData
159 ) -> ConfigFlowResult:
160 """Finished config flow and create entry."""
164 CONF_USERNAME: username,
165 CONF_USER_DATA: user_data.as_dict(),
166 CONF_BASE_URL: client.base_url,
173 config_entry: ConfigEntry,
174 ) -> RoborockOptionsFlowHandler:
175 """Create the options flow."""
180 """Handle an option flow for Roborock."""
182 def __init__(self, config_entry: ConfigEntry) ->
None:
183 """Initialize options flow."""
187 self, user_input: dict[str, Any] |
None =
None
188 ) -> ConfigFlowResult:
189 """Manage the options."""
193 self, user_input: dict[str, Any] |
None =
None
194 ) -> ConfigFlowResult:
195 """Manage the map object drawable options."""
196 if user_input
is not None:
197 self.
optionsoptions.setdefault(DRAWABLES, {}).
update(user_input)
200 for drawable, default_value
in DEFAULT_DRAWABLES.items():
205 drawable, default_value
211 data_schema=vol.Schema(data_schema),
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult _create_entry(self, RoborockApiClient client, str username, UserData user_data)
ConfigFlowResult async_step_reauth_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_code(self, dict[str, Any]|None user_input=None)
RoborockOptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
None __init__(self, ConfigEntry config_entry)
ConfigFlowResult async_step_drawables(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_init(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_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)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
_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)
web.Response get(self, web.Request request, str config_key)
IssData update(pyiss.ISS iss)