1 """Config Flow for Tessie integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
6 from http
import HTTPStatus
9 from aiohttp
import ClientConnectionError, ClientResponseError
10 from tessie_api
import get_state_of_all_vehicles
11 import voluptuous
as vol
17 from .const
import DOMAIN
19 TESSIE_SCHEMA = vol.Schema({vol.Required(CONF_ACCESS_TOKEN): str})
20 DESCRIPTION_PLACEHOLDERS = {
22 "url":
"[my.tessie.com/settings/api](https://my.tessie.com/settings/api)",
27 """Config Tessie API connection."""
32 self, user_input: Mapping[str, Any] |
None =
None
33 ) -> ConfigFlowResult:
34 """Get configuration from the user."""
35 errors: dict[str, str] = {}
39 await get_state_of_all_vehicles(
41 api_key=user_input[CONF_ACCESS_TOKEN],
44 except ClientResponseError
as e:
45 if e.status == HTTPStatus.UNAUTHORIZED:
46 errors[CONF_ACCESS_TOKEN] =
"invalid_access_token"
48 errors[
"base"] =
"unknown"
49 except ClientConnectionError:
50 errors[
"base"] =
"cannot_connect"
59 data_schema=TESSIE_SCHEMA,
60 description_placeholders=DESCRIPTION_PLACEHOLDERS,
65 self, entry_data: Mapping[str, Any]
66 ) -> ConfigFlowResult:
71 self, user_input: Mapping[str, Any] |
None =
None
72 ) -> ConfigFlowResult:
73 """Get update API Key from the user."""
74 errors: dict[str, str] = {}
78 await get_state_of_all_vehicles(
80 api_key=user_input[CONF_ACCESS_TOKEN],
82 except ClientResponseError
as e:
83 if e.status == HTTPStatus.UNAUTHORIZED:
84 errors[CONF_ACCESS_TOKEN] =
"invalid_access_token"
86 errors[
"base"] =
"unknown"
87 except ClientConnectionError:
88 errors[
"base"] =
"cannot_connect"
95 step_id=
"reauth_confirm",
96 data_schema=TESSIE_SCHEMA,
97 description_placeholders=DESCRIPTION_PLACEHOLDERS,
ConfigFlowResult async_step_user(self, Mapping[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth_confirm(self, Mapping[str, Any]|None user_input=None)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
ConfigEntry _get_reauth_entry(self)
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)
None _async_abort_entries_match(self, dict[str, Any]|None match_dict=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)
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)