1 """Config flow for LaCrosse View integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from lacrosse_view
import LaCrosse, Location, LoginError
10 import voluptuous
as vol
17 from .const
import DOMAIN
19 STEP_USER_DATA_SCHEMA = vol.Schema(
21 vol.Required(
"username"): str,
22 vol.Required(
"password"): str,
25 _LOGGER = logging.getLogger(__name__)
28 async
def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> list[Location]:
29 """Validate the user input allows us to connect."""
34 if await api.login(data[
"username"], data[
"password"]):
35 _LOGGER.debug(
"Successfully logged in")
37 locations = await api.get_locations()
38 _LOGGER.debug(locations)
39 except LoginError
as error:
40 raise InvalidAuth
from error
43 raise NoLocations(f
'No locations found for account {data["username"]}')
49 """Handle a config flow for LaCrosse View."""
54 """Initialize the config flow."""
55 self.
datadata: dict[str, str] = {}
56 self.
locationslocations: list[Location] = []
59 self, user_input: dict[str, Any] |
None =
None
60 ) -> ConfigFlowResult:
61 """Handle the initial step."""
62 if user_input
is None:
63 _LOGGER.debug(
"Showing initial form")
65 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA
73 _LOGGER.exception(
"Could not login")
74 errors[
"base"] =
"invalid_auth"
76 errors[
"base"] =
"no_locations"
78 _LOGGER.exception(
"Unexpected exception")
79 errors[
"base"] =
"unknown"
90 _LOGGER.debug(
"Moving on to location step")
93 _LOGGER.debug(
"Showing errors")
95 step_id=
"user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
99 self, user_input: dict[str, Any] |
None =
None
100 ) -> ConfigFlowResult:
101 """Handle the location step."""
104 _LOGGER.debug(
"Showing initial location selection")
107 data_schema=vol.Schema(
109 vol.Required(
"location"): vol.In(
110 {location.id: location.name
for location
in self.
locationslocations}
116 location_id = user_input[
"location"]
118 location_name = next(
119 location.name
for location
in self.
locationslocations
if location.id == location_id
129 "name": location_name,
130 "username": self.
datadata[
"username"],
131 "password": self.
datadata[
"password"],
136 self, entry_data: Mapping[str, Any]
137 ) -> ConfigFlowResult:
138 """Reauth in case of a password change or other error."""
143 """Error to indicate there is invalid auth."""
146 class NoLocations(HomeAssistantError):
147 """Error to indicate there are no locations."""
151 """Error to indicate that the entry does not exist when it should."""
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_location(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry _get_reauth_entry(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_update_reload_and_abort(self, ConfigEntry entry, *str|None|UndefinedType unique_id=UNDEFINED, str|UndefinedType title=UNDEFINED, Mapping[str, Any]|UndefinedType data=UNDEFINED, Mapping[str, Any]|UndefinedType data_updates=UNDEFINED, Mapping[str, Any]|UndefinedType options=UNDEFINED, str|UndefinedType reason=UNDEFINED, bool reload_even_if_entry_is_unchanged=True)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=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)
list[Location] validate_input(HomeAssistant hass, dict[str, Any] data)
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)