1 """Config flow for Linear Garage Door integration."""
3 from __future__
import annotations
5 from collections.abc
import Collection, Mapping, Sequence
10 from linear_garage_door
import Linear
11 from linear_garage_door.errors
import InvalidLoginError
12 import voluptuous
as vol
20 from .const
import DOMAIN
22 _LOGGER = logging.getLogger(__name__)
24 STEP_USER_DATA_SCHEMA = {
25 vol.Required(CONF_EMAIL): str,
26 vol.Required(CONF_PASSWORD): str,
33 ) -> dict[str, Sequence[Collection[str]]]:
34 """Validate the user input allows us to connect.
36 Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
41 device_id =
str(uuid.uuid4())
50 sites = await hub.get_sites()
51 except InvalidLoginError
as err:
52 raise InvalidAuth
from err
57 "email": data[
"email"],
58 "password": data[
"password"],
60 "device_id": device_id,
65 """Handle a config flow for Linear Garage Door."""
70 """Initialize the config flow."""
71 self.
datadata: dict[str, Sequence[Collection[str]]] = {}
74 self, user_input: dict[str, Any] |
None =
None
75 ) -> ConfigFlowResult:
76 """Handle the initial step."""
77 data_schema = vol.Schema(STEP_USER_DATA_SCHEMA)
79 if user_input
is None:
87 errors[
"base"] =
"invalid_auth"
89 _LOGGER.exception(
"Unexpected exception")
90 errors[
"base"] =
"unknown"
99 CONF_EMAIL: self.
datadata[
"email"],
100 CONF_PASSWORD: self.
datadata[
"password"],
107 step_id=
"user", data_schema=data_schema, errors=errors
112 user_input: dict[str, Any] |
None =
None,
113 ) -> ConfigFlowResult:
114 """Handle the site step."""
116 if isinstance(self.
datadata[
"sites"], list):
117 sites: list[dict[str, str]] = self.
datadata[
"sites"]
122 data_schema=vol.Schema(
124 vol.Required(
"site"): vol.In(
125 {site[
"id"]: site[
"name"]
for site
in sites}
131 site_id = user_input[
"site"]
133 site_name = next(site[
"name"]
for site
in sites
if site[
"id"] == site_id)
142 "email": self.
datadata[
"email"],
143 "password": self.
datadata[
"password"],
144 "device_id": self.
datadata[
"device_id"],
149 self, entry_data: Mapping[str, Any]
150 ) -> ConfigFlowResult:
151 """Reauth in case of a password change or other error."""
156 """Error to indicate there is invalid auth."""
159 class InvalidDeviceID(HomeAssistantError):
160 """Error to indicate there is invalid device ID."""
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_site(self, dict[str, Any]|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 _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)
dict[str, Sequence[Collection[str]]] validate_input(HomeAssistant hass, dict[str, str] 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)