diff --git a/homeassistant/components/tesla_fleet/__init__.py b/homeassistant/components/tesla_fleet/__init__.py index 3e14e5ad2b2f02..38a5900fcc1c59 100644 --- a/homeassistant/components/tesla_fleet/__init__.py +++ b/homeassistant/components/tesla_fleet/__init__.py @@ -1,6 +1,5 @@ """Tesla Fleet integration.""" -import asyncio from typing import Final from aiohttp.client_exceptions import ClientResponseError @@ -83,29 +82,26 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslaFleetConfigEntry) - region: str = token["ou_code"].lower() oauth_session = OAuth2Session(hass, entry, implementation) - refresh_lock = asyncio.Lock() - async def _refresh_token() -> str: - async with refresh_lock: - try: - await oauth_session.async_ensure_token_valid() - except ClientResponseError as e: - if e.status == 401: - raise ConfigEntryAuthFailed from e - raise ConfigEntryNotReady from e - token: str = oauth_session.token[CONF_ACCESS_TOKEN] - return token + async def _get_access_token() -> str: + try: + await oauth_session.async_ensure_token_valid() + except ClientResponseError as e: + if e.status == 401: + raise ConfigEntryAuthFailed from e + raise ConfigEntryNotReady from e + token: str = oauth_session.token[CONF_ACCESS_TOKEN] + return token # Create API connection tesla = TeslaFleetApi( session=session, - access_token=access_token, + access_token=_get_access_token, region=region, charging_scope=False, partner_scope=False, energy_scope=Scope.ENERGY_DEVICE_DATA in scopes, vehicle_scope=Scope.VEHICLE_DEVICE_DATA in scopes, - refresh_hook=_refresh_token, ) try: products = (await tesla.products())["response"] diff --git a/homeassistant/components/tesla_fleet/manifest.json b/homeassistant/components/tesla_fleet/manifest.json index 549f0a29ac264d..b05722af3e1b8d 100644 --- a/homeassistant/components/tesla_fleet/manifest.json +++ b/homeassistant/components/tesla_fleet/manifest.json @@ -8,5 +8,5 @@ "integration_type": "hub", "iot_class": "cloud_polling", "loggers": ["tesla-fleet-api"], - "requirements": ["tesla-fleet-api==1.2.7"] + "requirements": ["tesla-fleet-api==1.3.0"] } diff --git a/homeassistant/components/teslemetry/manifest.json b/homeassistant/components/teslemetry/manifest.json index b40a67dbff0b83..c67cc6463b14b1 100644 --- a/homeassistant/components/teslemetry/manifest.json +++ b/homeassistant/components/teslemetry/manifest.json @@ -7,5 +7,5 @@ "integration_type": "hub", "iot_class": "cloud_polling", "loggers": ["tesla-fleet-api"], - "requirements": ["tesla-fleet-api==1.2.7", "teslemetry-stream==0.7.10"] + "requirements": ["tesla-fleet-api==1.3.0", "teslemetry-stream==0.7.10"] } diff --git a/homeassistant/components/tessie/manifest.json b/homeassistant/components/tessie/manifest.json index a81197445a03fb..2025c9c2eaeee3 100644 --- a/homeassistant/components/tessie/manifest.json +++ b/homeassistant/components/tessie/manifest.json @@ -7,5 +7,5 @@ "integration_type": "hub", "iot_class": "cloud_polling", "loggers": ["tessie", "tesla-fleet-api"], - "requirements": ["tessie-api==0.1.1", "tesla-fleet-api==1.2.7"] + "requirements": ["tessie-api==0.1.1", "tesla-fleet-api==1.3.0"] } diff --git a/requirements_all.txt b/requirements_all.txt index 98e28a0af99f6a..14d24d7d621f0b 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2978,7 +2978,7 @@ temperusb==1.6.1 # homeassistant.components.tesla_fleet # homeassistant.components.teslemetry # homeassistant.components.tessie -tesla-fleet-api==1.2.7 +tesla-fleet-api==1.3.0 # homeassistant.components.powerwall tesla-powerwall==0.5.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 31ae7f58a858d0..1488a9dbd13856 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2478,7 +2478,7 @@ temperusb==1.6.1 # homeassistant.components.tesla_fleet # homeassistant.components.teslemetry # homeassistant.components.tessie -tesla-fleet-api==1.2.7 +tesla-fleet-api==1.3.0 # homeassistant.components.powerwall tesla-powerwall==0.5.2