1 """Config Flow for Teslemetry integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
8 from aiohttp
import ClientConnectionError
9 from tesla_fleet_api
import Teslemetry
10 from tesla_fleet_api.exceptions
import (
15 import voluptuous
as vol
21 from .const
import DOMAIN, LOGGER
23 TESLEMETRY_SCHEMA = vol.Schema({vol.Required(CONF_ACCESS_TOKEN): str})
24 DESCRIPTION_PLACEHOLDERS = {
26 "short_url":
"teslemetry.com/console",
27 "url":
"[teslemetry.com/console](https://teslemetry.com/console)",
32 """Config Teslemetry API connection."""
37 async
def async_auth(self, user_input: Mapping[str, Any]) -> dict[str, str]:
38 """Reusable Auth Helper."""
39 teslemetry = Teslemetry(
41 access_token=user_input[CONF_ACCESS_TOKEN],
44 metadata = await teslemetry.metadata()
46 return {CONF_ACCESS_TOKEN:
"invalid_access_token"}
47 except SubscriptionRequired:
48 return {
"base":
"subscription_required"}
49 except ClientConnectionError:
50 return {
"base":
"cannot_connect"}
51 except TeslaFleetError
as e:
53 return {
"base":
"unknown"}
59 self, user_input: Mapping[str, Any] |
None =
None
60 ) -> ConfigFlowResult:
61 """Get configuration from the user."""
62 errors: dict[str, str] = {}
63 if user_input
and not (errors := await self.
async_authasync_auth(user_input)):
72 data_schema=TESLEMETRY_SCHEMA,
73 description_placeholders=DESCRIPTION_PLACEHOLDERS,
78 self, entry_data: Mapping[str, Any]
79 ) -> ConfigFlowResult:
80 """Handle reauth on failure."""
84 self, user_input: Mapping[str, Any] |
None =
None
85 ) -> ConfigFlowResult:
86 """Handle users reauth credentials."""
88 errors: dict[str, str] = {}
90 if user_input
and not (errors := await self.
async_authasync_auth(user_input)):
97 step_id=
"reauth_confirm",
98 description_placeholders=DESCRIPTION_PLACEHOLDERS,
99 data_schema=TESLEMETRY_SCHEMA,
dict[str, str] async_auth(self, Mapping[str, Any] user_input)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)
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)
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_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)