1 """Config flow for Modern Forms."""
3 from __future__
import annotations
7 from aiomodernforms
import ModernFormsConnectionError, ModernFormsDevice
8 import voluptuous
as vol
15 from .const
import DOMAIN
17 USER_SCHEMA = vol.Schema({vol.Required(CONF_HOST): str})
21 """Handle a ModernForms config flow."""
25 host: str |
None =
None
26 mac: str |
None =
None
30 self, user_input: dict[str, Any] |
None =
None
31 ) -> ConfigFlowResult:
32 """Handle setup by user for Modern Forms integration."""
33 return await self._handle_config_flow(user_input)
36 self, discovery_info: zeroconf.ZeroconfServiceInfo
37 ) -> ConfigFlowResult:
38 """Handle zeroconf discovery."""
39 host = discovery_info.hostname.rstrip(
".")
40 name, _ = host.rsplit(
".")
42 self.context[
"title_placeholders"] = {
"name": name}
43 self.
hosthost = discovery_info.host
44 self.
macmac = discovery_info.properties.get(CONF_MAC)
48 return await self._handle_config_flow({},
True)
50 async
def async_step_zeroconf_confirm(
51 self, user_input: dict[str, Any] |
None =
None
52 ) -> ConfigFlowResult:
53 """Handle a flow initiated by zeroconf."""
54 return await self._handle_config_flow(user_input)
56 async
def _handle_config_flow(
57 self, user_input: dict[str, Any] |
None =
None, prepare: bool =
False
58 ) -> ConfigFlowResult:
59 """Config flow handler for ModernForms."""
61 if user_input
is None:
66 step_id=
"zeroconf_confirm",
67 description_placeholders={
"name": self.
namename},
71 data_schema=USER_SCHEMA,
75 user_input[CONF_HOST] = self.
hosthost
76 user_input[CONF_MAC] = self.
macmac
78 if user_input.get(CONF_MAC)
is None or not prepare:
80 device = ModernFormsDevice(user_input[CONF_HOST], session=session)
82 device = await device.update()
83 except ModernFormsConnectionError:
88 data_schema=USER_SCHEMA,
89 errors={
"base":
"cannot_connect"},
91 user_input[CONF_MAC] = device.info.mac_address
97 title = device.info.device_name
102 return await self.async_step_zeroconf_confirm()
106 data={CONF_HOST: user_input[CONF_HOST], CONF_MAC: user_input[CONF_MAC]},
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_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
ConfigFlowResult async_step_zeroconf(self, ZeroconfServiceInfo discovery_info)
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)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)