tesla-fleet-api 0.7.0__py3-none-any.whl → 0.7.1__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- tesla_fleet_api/const.py +1 -1
- tesla_fleet_api/exceptions.py +6 -1
- tesla_fleet_api/teslafleetapi.py +16 -1
- {tesla_fleet_api-0.7.0.dist-info → tesla_fleet_api-0.7.1.dist-info}/METADATA +1 -1
- {tesla_fleet_api-0.7.0.dist-info → tesla_fleet_api-0.7.1.dist-info}/RECORD +8 -8
- {tesla_fleet_api-0.7.0.dist-info → tesla_fleet_api-0.7.1.dist-info}/LICENSE +0 -0
- {tesla_fleet_api-0.7.0.dist-info → tesla_fleet_api-0.7.1.dist-info}/WHEEL +0 -0
- {tesla_fleet_api-0.7.0.dist-info → tesla_fleet_api-0.7.1.dist-info}/top_level.txt +0 -0
tesla_fleet_api/const.py
CHANGED
tesla_fleet_api/exceptions.py
CHANGED
@@ -363,7 +363,12 @@ async def raise_for_status(resp: aiohttp.ClientResponse) -> None:
|
|
363
363
|
elif resp.status == 424:
|
364
364
|
raise InvalidResponse(data)
|
365
365
|
elif resp.status == 429:
|
366
|
-
raise RateLimited(
|
366
|
+
raise RateLimited(
|
367
|
+
{
|
368
|
+
"reset": resp.headers.get("RateLimit-Reset"),
|
369
|
+
"after": resp.headers.get("Retry-After"),
|
370
|
+
}
|
371
|
+
)
|
367
372
|
elif resp.status == 451:
|
368
373
|
raise ResourceUnavailableForLegalReasons(data)
|
369
374
|
elif resp.status == 499:
|
tesla_fleet_api/teslafleetapi.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
"""Tesla Fleet API for Python."""
|
2
2
|
|
3
3
|
from json import dumps
|
4
|
-
from typing import Any
|
4
|
+
from typing import Any, Awaitable
|
5
5
|
import aiohttp
|
6
6
|
|
7
7
|
from .exceptions import raise_for_status, InvalidRegion, LibraryError, ResponseError
|
@@ -22,6 +22,7 @@ class TeslaFleetApi:
|
|
22
22
|
server: str | None = None
|
23
23
|
session: aiohttp.ClientSession
|
24
24
|
headers: dict[str, str]
|
25
|
+
refresh_hook: Awaitable | None
|
25
26
|
|
26
27
|
def __init__(
|
27
28
|
self,
|
@@ -34,11 +35,13 @@ class TeslaFleetApi:
|
|
34
35
|
partner_scope: bool = True,
|
35
36
|
user_scope: bool = True,
|
36
37
|
vehicle_scope: bool = True,
|
38
|
+
refresh_hook: Awaitable | None = None,
|
37
39
|
):
|
38
40
|
"""Initialize the Tesla Fleet API."""
|
39
41
|
|
40
42
|
self.session = session
|
41
43
|
self.access_token = access_token
|
44
|
+
self.refresh_hook = refresh_hook
|
42
45
|
|
43
46
|
if server is not None:
|
44
47
|
self.server = server
|
@@ -90,6 +93,10 @@ class TeslaFleetApi:
|
|
90
93
|
if method == Method.GET and json is not None:
|
91
94
|
raise ValueError("GET requests cannot have a body.")
|
92
95
|
|
96
|
+
# Call a pre-request hook if provided
|
97
|
+
if self.refresh_hook is not None:
|
98
|
+
await self.refresh_hook()
|
99
|
+
|
93
100
|
LOGGER.debug("Sending request to %s", path)
|
94
101
|
|
95
102
|
# Remove None values from params and json
|
@@ -114,8 +121,16 @@ class TeslaFleetApi:
|
|
114
121
|
LOGGER.debug("Response Status: %s", resp.status)
|
115
122
|
if "x-txid" in resp.headers:
|
116
123
|
LOGGER.debug("Response TXID: %s", resp.headers["x-txid"])
|
124
|
+
if "RateLimit-Reset" in resp.headers:
|
125
|
+
LOGGER.debug(
|
126
|
+
"Rate limit reset: %s", resp.headers.get("RateLimit-Reset")
|
127
|
+
)
|
128
|
+
if "Retry-After" in resp.headers:
|
129
|
+
LOGGER.debug("Retry after: %s", resp.headers.get("Retry-After"))
|
130
|
+
|
117
131
|
if not resp.ok:
|
118
132
|
await raise_for_status(resp)
|
133
|
+
|
119
134
|
if not resp.content_type.lower().startswith("application/json"):
|
120
135
|
LOGGER.debug("Response type is: %s", resp.content_type)
|
121
136
|
raise ResponseError(status=resp.status, data=await resp.text())
|
@@ -1,11 +1,11 @@
|
|
1
1
|
tesla_fleet_api/__init__.py,sha256=-OhrvoMVLeo13dDCjsltCacLxPqe2UODvSgHFdjyteA,639
|
2
2
|
tesla_fleet_api/charging.py,sha256=N_mc8axrXj3iduqLj_jCt4Vx86tHqe3xqQT4R1R7HvU,1689
|
3
|
-
tesla_fleet_api/const.py,sha256=
|
3
|
+
tesla_fleet_api/const.py,sha256=fMx1jUvELzTRrgoTN_OlN-eiQX0ets8E5pIQ8K8mPVQ,9277
|
4
4
|
tesla_fleet_api/energy.py,sha256=yOKNPyXWKMT7Z9a5RqdNksHokLRo657SWjly1bP2_Qs,5827
|
5
5
|
tesla_fleet_api/energyspecific.py,sha256=zggN-q0tf6EH_57bM4EuQ-IdcemKP0o-xv__LArRNnA,4147
|
6
|
-
tesla_fleet_api/exceptions.py,sha256=
|
6
|
+
tesla_fleet_api/exceptions.py,sha256=0-qeJUfyUGUcm2R3_W4OuGImgshY92ApSixl_CRM8ak,11171
|
7
7
|
tesla_fleet_api/partner.py,sha256=1vIBUaxKLIfqcC0X6VXZN0dMAzj_CLNPUMjA6QVqZ1k,1223
|
8
|
-
tesla_fleet_api/teslafleetapi.py,sha256=
|
8
|
+
tesla_fleet_api/teslafleetapi.py,sha256=725WSE3eeHwTvVY0pXqEiZNP4M5n2Op0c3q5cJIkPeY,5421
|
9
9
|
tesla_fleet_api/teslafleetoauth.py,sha256=OY9yRQuokYo3ts0C8Qb6Z-o9NNAGHbX9F5mHfAh50fo,4121
|
10
10
|
tesla_fleet_api/teslafleetopensource.py,sha256=TJfVPcqJlA1b3kMoGuLr-g5Gn8UDyYsTZhjvGY1MtIk,2007
|
11
11
|
tesla_fleet_api/teslemetry.py,sha256=kcZG7O9tsBt0BoUyCUSU9j9yCbN1qJDL1iUUo4DFESs,2167
|
@@ -13,8 +13,8 @@ tesla_fleet_api/tessie.py,sha256=4dBYxe1G2v9JvJGRbb01wXrAmvWT4jOfV4f_VQE_vkE,230
|
|
13
13
|
tesla_fleet_api/user.py,sha256=TZE2oh-n5zrhKXmGRuiNL9voKVODD7rBhGE_IObYVGA,1179
|
14
14
|
tesla_fleet_api/vehicle.py,sha256=KFFotHSmzaC4MhIlU8hoG7SVvPiV3_FC__uJf8BG_G0,31412
|
15
15
|
tesla_fleet_api/vehiclespecific.py,sha256=Nr4zZzfmIuw3RFYjQEX6c_xtYZgztMsN5ohVn-YEH0I,20600
|
16
|
-
tesla_fleet_api-0.7.
|
17
|
-
tesla_fleet_api-0.7.
|
18
|
-
tesla_fleet_api-0.7.
|
19
|
-
tesla_fleet_api-0.7.
|
20
|
-
tesla_fleet_api-0.7.
|
16
|
+
tesla_fleet_api-0.7.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
17
|
+
tesla_fleet_api-0.7.1.dist-info/METADATA,sha256=nazwokUo30zFvNPt79tKCs9Kx0nbrEf3LR0Htv_9QNA,3821
|
18
|
+
tesla_fleet_api-0.7.1.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
|
19
|
+
tesla_fleet_api-0.7.1.dist-info/top_level.txt,sha256=jeNbog_1saXBFrGpom9WyPWmilxsyP3szL_G7JLWQfM,16
|
20
|
+
tesla_fleet_api-0.7.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|