Adds MFA Capability to Tesla Integration

This commit is contained in:
BreakingBread0
2021-07-20 17:08:26 +00:00
parent 08f03c95d2
commit ff41cf1507
4 changed files with 10 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ from homeassistant.helpers.httpx_client import SERVER_SOFTWARE, USER_AGENT
from .const import (
CONF_EXPIRATION,
CONF_MFA,
CONF_WAKE_ON_START,
DEFAULT_SCAN_INTERVAL,
DEFAULT_WAKE_ON_START,
@@ -99,6 +100,7 @@ class TeslaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
{
vol.Required(CONF_USERNAME, default=self.username): str,
vol.Required(CONF_PASSWORD): str,
vol.Optional(CONF_MFA): str,
}
)
@@ -158,7 +160,9 @@ async def validate_input(hass: core.HomeAssistant, data):
password=data[CONF_PASSWORD],
update_interval=DEFAULT_SCAN_INTERVAL,
)
result = await controller.connect(test_login=True)
result = await controller.connect(
test_login=True, mfa_code=(data[CONF_MFA] if CONF_MFA in data else "")
)
config[CONF_TOKEN] = result["refresh_token"]
config[CONF_ACCESS_TOKEN] = result["access_token"]
config[CONF_EXPIRATION] = result[CONF_EXPIRATION]

View File

@@ -1,6 +1,7 @@
"""Const file for Tesla cars."""
CONF_EXPIRATION = "expiration"
CONF_WAKE_ON_START = "enable_wake_on_start"
CONF_MFA = "mfa"
DOMAIN = "tesla"
DATA_LISTENER = "listener"
DEFAULT_SCAN_INTERVAL = 660

View File

@@ -13,7 +13,8 @@
"user": {
"data": {
"username": "[%key:common::config_flow::data::email%]",
"password": "[%key:common::config_flow::data::password%]"
"password": "[%key:common::config_flow::data::password%]",
"mfa": "MFA Code"
},
"description": "Please enter your information.",
"title": "Tesla - Configuration"

View File

@@ -13,7 +13,8 @@
"user": {
"data": {
"password": "Password",
"username": "Email"
"username": "Email",
"mfa": "MFA Code"
},
"description": "Please enter your information.",
"title": "Tesla - Configuration"