Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions homeassistant/components/tesla_fleet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Tesla Fleet integration."""

import asyncio
from typing import Final

from aiohttp.client_exceptions import ClientResponseError
Expand Down Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/tesla_fleet/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
2 changes: 1 addition & 1 deletion homeassistant/components/teslemetry/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
2 changes: 1 addition & 1 deletion homeassistant/components/tessie/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
2 changes: 1 addition & 1 deletion requirements_all.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion requirements_test_all.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading