1 """Config flow for pushover integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from pushover_complete
import BadAPIRequestError, PushoverAPI
9 import voluptuous
as vol
15 from .const
import CONF_USER_KEY, DEFAULT_NAME, DOMAIN
17 USER_SCHEMA = vol.Schema(
19 vol.Optional(CONF_NAME, default=DEFAULT_NAME): str,
20 vol.Required(CONF_API_KEY): str,
21 vol.Required(CONF_USER_KEY): str,
26 async
def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, str]:
27 """Validate user input."""
29 pushover_api = PushoverAPI(data[CONF_API_KEY])
31 await hass.async_add_executor_job(pushover_api.validate, data[CONF_USER_KEY])
32 except BadAPIRequestError
as err:
33 if "application token is invalid" in str(err):
34 errors[CONF_API_KEY] =
"invalid_api_key"
35 elif "user key is invalid" in str(err):
36 errors[CONF_USER_KEY] =
"invalid_user_key"
38 errors[
"base"] =
"cannot_connect"
43 """Handle a config flow for pushover integration."""
45 _reauth_entry: ConfigEntry |
None
48 self, entry_data: Mapping[str, Any]
49 ) -> ConfigFlowResult:
50 """Perform reauth upon an API authentication error."""
51 self.
_reauth_entry_reauth_entry = self.hass.config_entries.async_get_entry(
52 self.context[
"entry_id"]
54 return await self.async_step_reauth_confirm()
56 async
def async_step_reauth_confirm(
57 self, user_input: dict[str, str] |
None =
None
58 ) -> ConfigFlowResult:
59 """Confirm reauth dialog."""
61 if user_input
is not None and self.
_reauth_entry_reauth_entry:
62 user_input = {**self.
_reauth_entry_reauth_entry.data, **user_input}
65 CONF_USER_KEY: user_input[CONF_USER_KEY],
66 CONF_API_KEY: user_input[CONF_API_KEY],
71 self.hass.config_entries.async_update_entry(
74 await self.hass.config_entries.async_reload(self.
_reauth_entry_reauth_entry.entry_id)
78 step_id=
"reauth_confirm",
79 data_schema=vol.Schema(
81 vol.Required(CONF_API_KEY): str,
88 self, user_input: dict[str, Any] |
None =
None
89 ) -> ConfigFlowResult:
90 """Handle the initial step."""
93 if user_input
is not None:
96 CONF_USER_KEY: user_input[CONF_USER_KEY],
97 CONF_API_KEY: user_input[CONF_API_KEY],
105 title=user_input[CONF_NAME],
111 data_schema=USER_SCHEMA,
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
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_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
None _async_abort_entries_match(self, dict[str, Any]|None match_dict=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)
dict[str, str] validate_input(HomeAssistant hass, dict[str, Any] data)