tesla-fleet-api 0.7.0__py3-none-any.whl → 0.7.2__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,7 @@ from .vehiclespecific import VehicleSpecific
15
15
  __all__ = [
16
16
  "TeslaFleetApi",
17
17
  "TeslaFleetOAuth",
18
+ "TeslaFleetOpenSource",
18
19
  "Teslemetry",
19
20
  "Tessie",
20
21
  "Charging",
tesla_fleet_api/const.py CHANGED
@@ -3,7 +3,7 @@
3
3
  from enum import Enum
4
4
  import logging
5
5
 
6
- VERSION = "0.7.0"
6
+ VERSION = "0.7.2"
7
7
  LOGGER = logging.getLogger(__package__)
8
8
  SERVERS = {
9
9
  "na": "https://fleet-api.prd.na.vn.cloud.tesla.com",
@@ -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(data)
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:
@@ -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,11 @@ 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
+ if access_token := await self.refresh_hook():
99
+ self.access_token = access_token
100
+
93
101
  LOGGER.debug("Sending request to %s", path)
94
102
 
95
103
  # Remove None values from params and json
@@ -114,8 +122,16 @@ class TeslaFleetApi:
114
122
  LOGGER.debug("Response Status: %s", resp.status)
115
123
  if "x-txid" in resp.headers:
116
124
  LOGGER.debug("Response TXID: %s", resp.headers["x-txid"])
125
+ if "RateLimit-Reset" in resp.headers:
126
+ LOGGER.debug(
127
+ "Rate limit reset: %s", resp.headers.get("RateLimit-Reset")
128
+ )
129
+ if "Retry-After" in resp.headers:
130
+ LOGGER.debug("Retry after: %s", resp.headers.get("Retry-After"))
131
+
117
132
  if not resp.ok:
118
133
  await raise_for_status(resp)
134
+
119
135
  if not resp.content_type.lower().startswith("application/json"):
120
136
  LOGGER.debug("Response type is: %s", resp.content_type)
121
137
  raise ResponseError(status=resp.status, data=await resp.text())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tesla_fleet_api
3
- Version: 0.7.0
3
+ Version: 0.7.2
4
4
  Summary: Tesla Fleet API library for Python
5
5
  Home-page: https://github.com/Teslemetry/tesla_fleet_api
6
6
  Author: Brett Adams
@@ -1,11 +1,11 @@
1
- tesla_fleet_api/__init__.py,sha256=-OhrvoMVLeo13dDCjsltCacLxPqe2UODvSgHFdjyteA,639
1
+ tesla_fleet_api/__init__.py,sha256=qGS4Qfp0uHaeK8UXOQVYjZ9rs_iR-CJ6rfCMLswphKA,667
2
2
  tesla_fleet_api/charging.py,sha256=N_mc8axrXj3iduqLj_jCt4Vx86tHqe3xqQT4R1R7HvU,1689
3
- tesla_fleet_api/const.py,sha256=oHOrKlioHra7rwxN0vNjw-ogFxmwuluUduYbX2aEbM8,9277
3
+ tesla_fleet_api/const.py,sha256=oMxY97yVTIRA94E2AejYiZ-Xe8WCEB9NPXaT2ufjXLc,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=BcvJyjY4qM2-Rf7ZMA94xPIN6ebKit89E7qattMmbr8,11018
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=S-7TH47aTuCi1LV4fLCxtvcCxuA0vyGC04XYBKHYG_4,4853
8
+ tesla_fleet_api/teslafleetapi.py,sha256=EJyfUq5X-rx7ruR6hKlSMLXLERLj2SBxT-YemiCIHcs,5490
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.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
17
- tesla_fleet_api-0.7.0.dist-info/METADATA,sha256=xJ4Byt3bVHwF_50-6-_WmqP9Z3OkTtiGKwS46UHltog,3821
18
- tesla_fleet_api-0.7.0.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
19
- tesla_fleet_api-0.7.0.dist-info/top_level.txt,sha256=jeNbog_1saXBFrGpom9WyPWmilxsyP3szL_G7JLWQfM,16
20
- tesla_fleet_api-0.7.0.dist-info/RECORD,,
16
+ tesla_fleet_api-0.7.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
17
+ tesla_fleet_api-0.7.2.dist-info/METADATA,sha256=yBS2vyPI8A7jgI2XNqDUsDangdsuAB60-0ZCO5KhzZE,3821
18
+ tesla_fleet_api-0.7.2.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
19
+ tesla_fleet_api-0.7.2.dist-info/top_level.txt,sha256=jeNbog_1saXBFrGpom9WyPWmilxsyP3szL_G7JLWQfM,16
20
+ tesla_fleet_api-0.7.2.dist-info/RECORD,,