Home Assistant Unofficial Reference 2024.12.1
config_flow.py
Go to the documentation of this file.
1 """Config flow for ecowitt."""
2 
3 from __future__ import annotations
4 
5 import secrets
6 from typing import Any
7 
8 from yarl import URL
9 
10 from homeassistant.components import webhook
11 from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
12 from homeassistant.const import CONF_WEBHOOK_ID
13 from homeassistant.exceptions import HomeAssistantError
14 from homeassistant.helpers.network import get_url
15 
16 from .const import DOMAIN
17 
18 
19 class EcowittConfigFlow(ConfigFlow, domain=DOMAIN):
20  """Config flow for the Ecowitt."""
21 
22  VERSION = 1
23  _webhook_id: str
24 
25  async def async_step_user(
26  self, user_input: dict[str, Any] | None = None
27  ) -> ConfigFlowResult:
28  """Handle the initial step."""
29  if user_input is None:
30  self._webhook_id_webhook_id = secrets.token_hex(16)
31  return self.async_show_formasync_show_formasync_show_form(
32  step_id="user",
33  )
34 
35  base_url = URL(get_url(self.hass))
36  assert base_url.host
37 
38  return self.async_create_entryasync_create_entryasync_create_entry(
39  title="Ecowitt",
40  data={
41  CONF_WEBHOOK_ID: self._webhook_id_webhook_id,
42  },
43  description_placeholders={
44  "path": webhook.async_generate_path(self._webhook_id_webhook_id),
45  "server": base_url.host,
46  "port": str(base_url.port),
47  },
48  )
49 
50 
52  """Error to indicate there port is not usable."""
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
Definition: config_flow.py:27
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)
str
_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)
str get_url(HomeAssistant hass, *bool require_current_request=False, bool require_ssl=False, bool require_standard_port=False, bool require_cloud=False, bool allow_internal=True, bool allow_external=True, bool allow_cloud=True, bool|None allow_ip=None, bool|None prefer_external=None, bool prefer_cloud=False)
Definition: network.py:131