Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow for VoIP integration."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from voip_utils import SIP_PORT
8 import voluptuous as vol
9 
10 from homeassistant.config_entries import (
11  ConfigEntry,
12  ConfigFlow,
13  ConfigFlowResult,
14  OptionsFlow,
15 )
16 from homeassistant.core import callback
17 from homeassistant.helpers import config_validation as cv
18 
19 from .const import CONF_SIP_PORT, DOMAIN
20 
21 
22 class VoIPConfigFlow(ConfigFlow, domain=DOMAIN):
23  """Handle a config flow for VoIP integration."""
24 
25  VERSION = 1
26 
27  async def async_step_user(
28  self, user_input: dict[str, Any] | None = None
29  ) -> ConfigFlowResult:
30  """Handle the initial step."""
31  if self._async_current_entries_async_current_entries():
32  return self.async_abortasync_abortasync_abort(reason="single_instance_allowed")
33 
34  if user_input is None:
35  return self.async_show_formasync_show_formasync_show_form(
36  step_id="user",
37  )
38 
39  return self.async_create_entryasync_create_entryasync_create_entry(
40  title="Voice over IP",
41  data=user_input,
42  )
43 
44  @staticmethod
45  @callback
47  config_entry: ConfigEntry,
48  ) -> OptionsFlow:
49  """Create the options flow."""
50  return VoipOptionsFlowHandler()
51 
52 
54  """Handle VoIP options."""
55 
56  async def async_step_init(
57  self, user_input: dict[str, Any] | None = None
58  ) -> ConfigFlowResult:
59  """Manage the options."""
60  if user_input is not None:
61  return self.async_create_entryasync_create_entry(title="", data=user_input)
62 
63  return self.async_show_formasync_show_form(
64  step_id="init",
65  data_schema=vol.Schema(
66  {
67  vol.Required(
68  CONF_SIP_PORT,
69  default=self.config_entryconfig_entryconfig_entry.options.get(
70  CONF_SIP_PORT,
71  SIP_PORT,
72  ),
73  ): cv.port
74  }
75  ),
76  )
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
Definition: config_flow.py:29
OptionsFlow async_get_options_flow(ConfigEntry config_entry)
Definition: config_flow.py:48
ConfigFlowResult async_step_init(self, dict[str, Any]|None user_input=None)
Definition: config_flow.py:58
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)
list[ConfigEntry] _async_current_entries(self, bool|None include_ignore=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)
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)