1 """Config flow for Soma."""
6 from api.soma_api
import SomaApi
7 from requests
import RequestException
8 import voluptuous
as vol
13 from .const
import DOMAIN
15 _LOGGER = logging.getLogger(__name__)
21 """Handle a config flow."""
26 """Instantiate config flow."""
29 self, user_input: dict[str, Any] |
None =
None
30 ) -> ConfigFlowResult:
31 """Handle a flow start."""
32 if user_input
is None:
34 vol.Required(CONF_HOST): str,
35 vol.Required(CONF_PORT, default=DEFAULT_PORT): int,
38 return self.async_show_form(step_id=
"user", data_schema=vol.Schema(data))
40 return await self.async_step_creation(user_input)
43 """Finish config flow."""
45 api = await self.hass.async_add_executor_job(
46 SomaApi, user_input[
"host"], user_input[
"port"]
48 except RequestException:
49 _LOGGER.error(
"Connection to SOMA Connect failed with RequestException")
52 result = await self.hass.async_add_executor_job(api.list_devices)
53 _LOGGER.debug(
"Successfully set up Soma Connect")
54 if result[
"result"] ==
"success":
57 data={
"host": user_input[
"host"],
"port": user_input[
"port"]},
60 "Connection to SOMA Connect failed (result:%s)", result[
"result"]
63 except RequestException:
64 _LOGGER.error(
"Connection to SOMA Connect failed with RequestException")
67 _LOGGER.error(
"Connection to SOMA Connect failed with KeyError")
71 """Handle flow start from existing config section."""
ConfigFlowResult async_step_creation(self, dict[str, Any] user_input)
ConfigFlowResult async_step_import(self, dict[str, Any] import_data)
ConfigFlowResult async_step_user(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_abort(self, *str reason, Mapping[str, str]|None description_placeholders=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)