1 """Config flow to configure the Freebox integration."""
6 from freebox_api.exceptions
import AuthorizationError, HttpRequestError
7 import voluptuous
as vol
13 from .const
import DOMAIN
14 from .router
import get_api, get_hosts_list_if_supported
16 _LOGGER = logging.getLogger(__name__)
20 """Handle a config flow."""
25 """Initialize config flow."""
26 self.
_data_data: dict[str, Any] = {}
29 self, user_input: dict[str, Any] |
None =
None
30 ) -> ConfigFlowResult:
31 """Handle a flow initiated by the user."""
32 if user_input
is None:
35 data_schema=vol.Schema(
37 vol.Required(CONF_HOST): str,
38 vol.Required(CONF_PORT): int,
53 self, user_input: dict[str, Any] |
None =
None
54 ) -> ConfigFlowResult:
55 """Attempt to link with the Freebox router.
57 Given a configured host, will ask the user to press the button
58 to connect to the router.
60 if user_input
is None:
65 fbx = await
get_api(self.hass, self.
_data_data[CONF_HOST])
68 await fbx.open(self.
_data_data[CONF_HOST], self.
_data_data[CONF_PORT])
71 await fbx.system.get_config()
78 title=self.
_data_data[CONF_HOST],
82 except AuthorizationError
as error:
84 errors[
"base"] =
"register_failed"
86 except HttpRequestError:
88 "Error connecting to the Freebox router at %s", self.
_data_data[CONF_HOST]
90 errors[
"base"] =
"cannot_connect"
94 "Unknown error connecting with Freebox router at %s",
95 self.
_data_data[CONF_HOST],
97 errors[
"base"] =
"unknown"
102 self, discovery_info: zeroconf.ZeroconfServiceInfo
103 ) -> ConfigFlowResult:
104 """Initialize flow from zeroconf."""
105 zeroconf_properties = discovery_info.properties
106 host = zeroconf_properties[
"api_domain"]
107 port = zeroconf_properties[
"https_port"]
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_link(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_zeroconf(self, zeroconf.ZeroconfServiceInfo discovery_info)
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)
Freepybox get_api(HomeAssistant hass, str host)
tuple[bool, list[dict[str, Any]]] get_hosts_list_if_supported(Freepybox fbx_api)