Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow for Mullvad VPN integration."""
2 
3 from typing import Any
4 
5 from mullvad_api import MullvadAPI, MullvadAPIError
6 
7 from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
8 
9 from .const import DOMAIN
10 
11 
12 class MullvadConfigFlow(ConfigFlow, domain=DOMAIN):
13  """Handle a config flow for Mullvad VPN."""
14 
15  VERSION = 1
16 
17  async def async_step_user(
18  self, user_input: dict[str, Any] | None = None
19  ) -> ConfigFlowResult:
20  """Handle the initial step."""
21  errors = {}
22  if user_input is not None:
23  try:
24  await self.hass.async_add_executor_job(MullvadAPI)
25  except MullvadAPIError:
26  errors["base"] = "cannot_connect"
27  except Exception: # noqa: BLE001
28  errors["base"] = "unknown"
29  else:
30  return self.async_create_entryasync_create_entryasync_create_entry(title="Mullvad VPN", data=user_input)
31 
32  return self.async_show_formasync_show_formasync_show_form(step_id="user", errors=errors)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
Definition: config_flow.py:19
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)
_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)