Pass a websession and a client_id to the Tractive client in the config flow (#186120)

This commit is contained in:
Maciej Bieniek
2026-10-13 13:30:03 +02:00
committed by GitHub
parent f718458512
commit 5eeabe8d1b
@@ -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}