mirror of
https://github.com/home-assistant/core.git
synced 2026-12-04 04:41:30 -04:00
Pass a websession and a client_id to the Tractive client in the config flow (#186120)
This commit is contained in:
@@ -13,8 +13,9 @@ from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import DOMAIN
|
||||
from .const import CLIENT_ID, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -32,7 +33,12 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str,
|
||||
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
|
||||
"""
|
||||
|
||||
client = aiotractive.api.API(data[CONF_EMAIL], data[CONF_PASSWORD])
|
||||
client = aiotractive.api.API(
|
||||
data[CONF_EMAIL],
|
||||
data[CONF_PASSWORD],
|
||||
session=async_get_clientsession(hass),
|
||||
client_id=CLIENT_ID,
|
||||
)
|
||||
try:
|
||||
user_id = await client.user_id()
|
||||
except aiotractive.exceptions.UnauthorizedError as error:
|
||||
@@ -44,8 +50,6 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str,
|
||||
):
|
||||
raise RateLimitExceeded from error
|
||||
raise CannotConnect from error
|
||||
finally:
|
||||
await client.close()
|
||||
|
||||
return {"title": data[CONF_EMAIL], "user_id": user_id}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user