1 """Config flow for Ruuvi Gateway integration."""
3 from __future__
import annotations
8 import aioruuvigateway.api
as gw_api
9 from aioruuvigateway.excs
import CannotConnect, InvalidAuth
18 from .schemata
import CONFIG_SCHEMA, get_config_schema_with_default_host
20 _LOGGER = logging.getLogger(__name__)
24 """Handle a config flow for Ruuvi Gateway."""
29 """Initialize the config flow."""
35 user_input: dict[str, Any],
36 ) -> tuple[ConfigFlowResult |
None, dict[str, str]]:
37 """Validate configuration (either discovered or user input)."""
38 errors: dict[str, str] = {}
42 resp = await gw_api.get_gateway_history_data(
44 host=user_input[CONF_HOST],
45 bearer_token=user_input[CONF_TOKEN],
48 format_mac(resp.gw_mac), raise_on_progress=
False
51 updates={CONF_HOST: user_input[CONF_HOST]}
53 info = {
"title": f
"Ruuvi Gateway {resp.gw_mac_suffix}"}
59 errors[
"base"] =
"cannot_connect"
61 errors[
"base"] =
"invalid_auth"
63 _LOGGER.exception(
"Unexpected exception")
64 errors[
"base"] =
"unknown"
69 user_input: dict[str, Any] |
None =
None,
70 ) -> ConfigFlowResult:
71 """Handle requesting or validating user input."""
72 if user_input
is not None:
75 result, errors =
None, {}
76 if result
is not None:
81 errors=(errors
or None),
85 self, discovery_info: dhcp.DhcpServiceInfo
86 ) -> ConfigFlowResult:
87 """Prepare configuration for a DHCP discovered Ruuvi Gateway."""
tuple[ConfigFlowResult|None, dict[str, str]] _async_validate(self, dict[str, Any] user_input)
ConfigFlowResult async_step_dhcp(self, dhcp.DhcpServiceInfo discovery_info)
ConfigFlowResult async_step_user(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_step_user(self, dict[str, Any]|None user_input=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)
vol.Schema get_config_schema_with_default_host(str host)
httpx.AsyncClient get_async_client(HomeAssistant hass, bool verify_ssl=True)