1 """Config flow for Wolf SmartSet Service integration."""
5 from httpcore
import ConnectError
6 import voluptuous
as vol
7 from wolf_comm.models
import Device
8 from wolf_comm.token_auth
import InvalidAuth
9 from wolf_comm.wolf_client
import WolfClient
14 from .const
import DEVICE_GATEWAY, DEVICE_ID, DEVICE_NAME, DOMAIN
16 _LOGGER = logging.getLogger(__name__)
18 USER_SCHEMA = vol.Schema(
19 {vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
24 """Handle a config flow for Wolf SmartSet Service."""
29 fetched_systems: list[Device]
32 """Initialize with empty username and password."""
33 self.
usernameusername: str |
None =
None
34 self.
passwordpassword: str |
None =
None
37 self, user_input: dict[str, str] |
None =
None
38 ) -> ConfigFlowResult:
39 """Handle the initial step to get connection parameters."""
41 if user_input
is not None:
42 wolf_client = WolfClient(
43 user_input[CONF_USERNAME], user_input[CONF_PASSWORD]
48 errors[
"base"] =
"cannot_connect"
50 errors[
"base"] =
"invalid_auth"
52 _LOGGER.exception(
"Unexpected exception")
53 errors[
"base"] =
"unknown"
55 self.
usernameusername = user_input[CONF_USERNAME]
56 self.
passwordpassword = user_input[CONF_PASSWORD]
59 step_id=
"user", data_schema=USER_SCHEMA, errors=errors
63 self, user_input: dict[str, str] |
None =
None
64 ) -> ConfigFlowResult:
65 """Allow user to select device from devices connected to specified account."""
66 errors: dict[str, str] = {}
67 if user_input
is not None:
68 device_name = user_input[DEVICE_NAME]
70 device
for device
in self.
fetched_systemsfetched_systems
if device.name == device_name
72 device_id = system[0].id
76 title=user_input[DEVICE_NAME],
78 CONF_USERNAME: self.
usernameusername,
79 CONF_PASSWORD: self.
passwordpassword,
80 DEVICE_NAME: device_name,
81 DEVICE_GATEWAY: system[0].gateway,
86 data_schema = vol.Schema(
88 vol.Required(DEVICE_NAME): vol.In(
94 step_id=
"device", data_schema=data_schema, errors=errors
ConfigFlowResult async_step_user(self, dict[str, str]|None user_input=None)
ConfigFlowResult async_step_device(self, dict[str, str]|None user_input=None)
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_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)