1 """Config flow for UpCloud."""
3 from __future__
import annotations
8 import requests.exceptions
10 import voluptuous
as vol
21 from .const
import DEFAULT_SCAN_INTERVAL, DOMAIN
23 _LOGGER = logging.getLogger(__name__)
27 """UpCloud config flow."""
35 self, user_input: dict[str, Any] |
None =
None
36 ) -> ConfigFlowResult:
37 """Handle user initiated flow."""
38 if user_input
is None:
43 manager = upcloud_api.CloudManager(
44 user_input[CONF_USERNAME], user_input[CONF_PASSWORD]
49 await self.hass.async_add_executor_job(manager.authenticate)
50 except upcloud_api.UpCloudAPIError:
51 errors[
"base"] =
"invalid_auth"
52 _LOGGER.debug(
"invalid_auth", exc_info=
True)
53 except requests.exceptions.RequestException:
54 errors[
"base"] =
"cannot_connect"
55 _LOGGER.debug(
"cannot_connect", exc_info=
True)
59 step_id=
"user", user_input=user_input, errors=errors
63 updates={CONF_PASSWORD: user_input[CONF_PASSWORD]}
71 user_input: dict[str, Any] |
None =
None,
72 errors: dict[str, str] |
None =
None,
73 ) -> ConfigFlowResult:
75 if user_input
is None:
79 data_schema=vol.Schema(
82 CONF_USERNAME, default=user_input.get(CONF_USERNAME,
"")
85 CONF_PASSWORD, default=user_input.get(CONF_PASSWORD,
"")
95 config_entry: ConfigEntry,
96 ) -> UpCloudOptionsFlow:
97 """Get options flow."""
102 """UpCloud options flow."""
105 self, user_input: dict[str, Any] |
None =
None
106 ) -> ConfigFlowResult:
107 """Handle options flow."""
109 if user_input
is not None:
112 data_schema = vol.Schema(
117 or DEFAULT_SCAN_INTERVAL.total_seconds(),
118 ): vol.All(vol.Coerce(int), vol.Range(min=30)),
121 return self.
async_show_formasync_show_form(step_id=
"init", data_schema=data_schema)
ConfigFlowResult _async_show_form(self, str step_id, dict[str, Any]|None user_input=None, dict[str, str]|None errors=None)
UpCloudOptionsFlow async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_user(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|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)
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)