1 """OpenTherm Gateway config flow."""
3 from __future__
import annotations
9 from pyotgw
import vars
as gw_vars
10 from serial
import SerialException
11 import voluptuous
as vol
35 CONF_TEMPORARY_OVRD_MODE,
42 """OpenTherm Gateway Config Flow."""
49 config_entry: ConfigEntry,
50 ) -> OpenThermGwOptionsFlow:
51 """Get the options flow for this handler."""
55 self, info: dict[str, Any] |
None =
None
56 ) -> ConfigFlowResult:
57 """Handle config flow initiation."""
59 name = info[CONF_NAME]
60 device = info[CONF_DEVICE]
61 gw_id = cv.slugify(info.get(CONF_ID, name))
65 if gw_id
in [e[CONF_ID]
for e
in entries]:
66 return self.
_show_form_show_form({
"base":
"id_exists"})
68 if device
in [e[CONF_DEVICE]
for e
in entries]:
69 return self.
_show_form_show_form({
"base":
"already_configured"})
72 """Try to connect to the OpenTherm Gateway."""
73 otgw = pyotgw.OpenThermGateway()
74 status = await otgw.connect(device)
75 await otgw.disconnect()
78 return status[OpenThermDataSource.GATEWAY].
get(gw_vars.OTGW_ABOUT)
81 async
with asyncio.timeout(CONNECTION_TIMEOUT):
84 return self.
_show_form_show_form({
"base":
"timeout_connect"})
85 except (ConnectionError, SerialException):
86 return self.
_show_form_show_form({
"base":
"cannot_connect"})
93 self, user_input: dict[str, Any] |
None =
None
94 ) -> ConfigFlowResult:
95 """Handle manual initiation of the config flow."""
100 """Import an OpenTherm Gateway device as a config entry.
102 This flow is triggered by `async_setup` for configured devices.
105 CONF_NAME: import_data.get(CONF_NAME, import_data[CONF_ID]),
106 CONF_DEVICE: import_data[CONF_DEVICE],
107 CONF_ID: import_data[CONF_ID],
109 return await self.
async_step_initasync_step_init(info=formatted_config)
111 def _show_form(self, errors: dict[str, str] |
None =
None) -> ConfigFlowResult:
112 """Show the config flow form with possible errors."""
115 data_schema=vol.Schema(
117 vol.Required(CONF_NAME): str,
118 vol.Required(CONF_DEVICE): str,
119 vol.Optional(CONF_ID): str,
126 """Create entry for the OpenTherm Gateway device."""
128 title=name, data={CONF_ID: gw_id, CONF_DEVICE: device, CONF_NAME: name}
133 """Handle opentherm_gw options."""
136 self, user_input: dict[str, Any] |
None =
None
137 ) -> ConfigFlowResult:
138 """Manage the opentherm_gw options."""
139 if user_input
is not None:
144 data_schema=vol.Schema(
152 [0, PRECISION_TENTHS, PRECISION_HALVES, PRECISION_WHOLE]
161 [0, PRECISION_TENTHS, PRECISION_HALVES, PRECISION_WHOLE]
165 CONF_TEMPORARY_OVRD_MODE,
167 CONF_TEMPORARY_OVRD_MODE,
True
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_init(self, dict[str, Any]|None info=None)
OpenThermGwOptionsFlow async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult _show_form(self, dict[str, str]|None errors=None)
ConfigFlowResult async_step_import(self, dict[str, Any] import_data)
def _create_entry(self, gw_id, name, device)
ConfigFlowResult async_step_init(self, dict[str, Any]|None user_input=None)
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_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)
ConfigEntry config_entry(self)
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)
web.Response get(self, web.Request request, str config_key)
str test_connection(HomeAssistant hass, str host, int port)