1 """Config flow for MyPermobil integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from mypermobil
import (
11 MyPermobilAPIException,
12 MyPermobilClientException,
13 MyPermobilEulaException,
15 import voluptuous
as vol
29 from .const
import APPLICATION, DOMAIN
31 _LOGGER = logging.getLogger(__name__)
33 GET_EMAIL_SCHEMA = vol.Schema(
41 GET_TOKEN_SCHEMA = vol.Schema({vol.Required(CONF_CODE): cv.string})
45 """Permobil config flow."""
48 region_names: dict[str, str] = {}
49 data: dict[str, str] = {}
52 """Initialize flow."""
55 self.
p_apip_api = MyPermobil(APPLICATION, session=session)
58 self, user_input: dict[str, Any] |
None =
None
59 ) -> ConfigFlowResult:
60 """Invoke when a user initiates a flow via the user interface."""
61 errors: dict[str, str] = {}
65 self.
p_apip_api.set_email(user_input[CONF_EMAIL])
66 except MyPermobilClientException:
67 _LOGGER.exception(
"Error validating email")
68 errors[
"base"] =
"invalid_email"
75 if errors
or not user_input:
77 step_id=
"user", data_schema=GET_EMAIL_SCHEMA, errors=errors
82 self, user_input: dict[str, Any] |
None =
None
83 ) -> ConfigFlowResult:
84 """Invoke when a user initiates a flow via the user interface."""
85 errors: dict[str, str] = {}
95 except MyPermobilAPIException:
96 _LOGGER.exception(
"Error requesting regions")
97 errors[
"base"] =
"region_fetch_error"
100 region_url = self.
region_namesregion_names[user_input[CONF_REGION]]
102 self.
datadata[CONF_REGION] = region_url
103 self.
p_apip_api.set_region(region_url)
104 _LOGGER.debug(
"region %s", self.
p_apip_api.region)
107 await self.
p_apip_api.request_application_code()
108 except MyPermobilAPIException:
109 _LOGGER.exception(
"Error requesting code")
110 errors[
"base"] =
"code_request_error"
112 if errors
or not user_input:
117 vol.Required(CONF_REGION): selector.SelectSelector(
118 selector.SelectSelectorConfig(
120 mode=selector.SelectSelectorMode.DROPDOWN,
126 step_id=
"region", data_schema=schema, errors=errors
132 self, user_input: dict[str, Any] |
None =
None
133 ) -> ConfigFlowResult:
134 """Second step in config flow to enter the email code."""
135 errors: dict[str, str] = {}
139 self.
p_apip_api.set_code(user_input[CONF_CODE])
141 token, ttl = await self.
p_apip_api.request_application_token()
142 self.
datadata[CONF_TOKEN] = token
143 self.
datadata[CONF_TTL] = ttl
144 except (MyPermobilAPIException, MyPermobilClientException):
147 _LOGGER.exception(
"Error verifying code")
148 errors[
"base"] =
"invalid_code"
149 except MyPermobilEulaException:
151 errors[
"base"] =
"unsigned_eula"
153 if errors
or not user_input:
155 step_id=
"email_code",
156 data_schema=GET_TOKEN_SCHEMA,
158 description_placeholders={
"app_name":
"MyPermobil"},
169 self, entry_data: Mapping[str, Any]
170 ) -> ConfigFlowResult:
171 """Perform reauth upon an API authentication error."""
173 email: str = entry_data[CONF_EMAIL]
174 region: str = entry_data[CONF_REGION]
175 self.
p_apip_api.set_email(email)
176 self.
p_apip_api.set_region(region)
181 await self.
p_apip_api.request_application_code()
182 except MyPermobilAPIException:
183 _LOGGER.exception(
"Error requesting code for reauth")
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_email_code(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_region(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)
HomeAssistant async_get_hass()
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)