Skip to content

Commit 1c455c6

Browse files
committed
Check token on every request
1 parent 7883360 commit 1c455c6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tesla_fleet_api/teslafleetoauth.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
from typing import Any
12
import aiohttp
23
import time
4+
5+
from tesla_fleet_api.const import Methods
36
from .teslafleetapi import TeslaFleetApi
47
from .const import Scopes, SERVERS
58

@@ -67,6 +70,7 @@ async def check_access_token(self) -> str | None:
6770
return await self.refresh_access_token()
6871

6972
async def refresh_access_token(self) -> str:
73+
"""Refresh the access token."""
7074
if not self.refresh_token:
7175
raise ValueError("Refresh token is missing")
7276
async with self.session.post(
@@ -82,3 +86,15 @@ async def refresh_access_token(self) -> str:
8286
self.refresh_token = data["refresh_token"]
8387
self.expires = int(time.time()) + data["expires_in"]
8488
return {"refresh_token": self.refresh_token, "expires": self.expires}
89+
90+
async def _request(
91+
self,
92+
method: Methods,
93+
path: str,
94+
params: dict | None = None,
95+
data: dict | None = None,
96+
json: dict | None = None,
97+
):
98+
"""Send a request to the Tesla Fleet API."""
99+
await self.check_access_token()
100+
return await super()._request(method, path, params, data, json)

0 commit comments

Comments
 (0)