1 """Config flow for Radio Thermostat integration."""
3 from __future__
import annotations
7 from urllib.error
import URLError
9 from radiotherm.validate
import RadiothermTstatError
10 import voluptuous
as vol
18 from .const
import DOMAIN
19 from .data
import RadioThermInitData, async_get_init_data
21 _LOGGER = logging.getLogger(__name__)
25 """Error to indicate we cannot connect."""
29 """Validate the connection."""
32 except (TimeoutError, RadiothermTstatError, URLError, OSError)
as ex:
33 raise CannotConnect(f
"Failed to connect to {host}: {ex}")
from ex
37 """Handle a config flow for Radio Thermostat."""
42 """Initialize ConfigFlow."""
47 self, discovery_info: dhcp.DhcpServiceInfo
48 ) -> ConfigFlowResult:
49 """Discover via DHCP."""
57 updates={CONF_HOST: discovery_info.ip}, reload_on_update=
False
64 self, user_input: dict[str, Any] |
None =
None
65 ) -> ConfigFlowResult:
66 """Attempt to confirm."""
69 assert ip_address
is not None
70 assert init_data
is not None
71 if user_input
is not None:
74 data={CONF_HOST: ip_address},
79 "name": init_data.name,
81 "model": init_data.model
or "Unknown",
83 self.context[
"title_placeholders"] = placeholders
86 description_placeholders=placeholders,
90 self, user_input: dict[str, Any] |
None =
None
91 ) -> ConfigFlowResult:
92 """Handle the initial step."""
94 if user_input
is not None:
98 errors[CONF_HOST] =
"cannot_connect"
100 _LOGGER.exception(
"Unexpected exception")
101 errors[
"base"] =
"unknown"
105 updates={CONF_HOST: user_input[CONF_HOST]},
106 reload_on_update=
False,
109 title=init_data.name,
115 data_schema=vol.Schema({vol.Required(CONF_HOST): str}),
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_confirm(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_dhcp(self, dhcp.DhcpServiceInfo discovery_info)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
None _set_confirm_only(self)
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_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
None _async_abort_entries_match(self, dict[str, Any]|None match_dict=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)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
RadioThermInitData validate_connection(HomeAssistant hass, str host)
RadioThermInitData async_get_init_data(HomeAssistant hass, str host)