tesla-fleet-api 0.8.1__tar.gz → 0.8.2__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. {tesla_fleet_api-0.8.1/tesla_fleet_api.egg-info → tesla_fleet_api-0.8.2}/PKG-INFO +1 -1
  2. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/setup.py +1 -1
  3. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/const.py +1 -1
  4. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/teslafleetapi.py +13 -14
  5. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/vehiclesigned.py +5 -8
  6. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2/tesla_fleet_api.egg-info}/PKG-INFO +1 -1
  7. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/LICENSE +0 -0
  8. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/README.md +0 -0
  9. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/setup.cfg +0 -0
  10. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/__init__.py +0 -0
  11. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/charging.py +0 -0
  12. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/energy.py +0 -0
  13. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/energyspecific.py +0 -0
  14. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/exceptions.py +0 -0
  15. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/partner.py +0 -0
  16. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/pb2/__init__.py +0 -0
  17. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/pb2/__init__.pyi +0 -0
  18. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/pb2/car_server_pb2.py +0 -0
  19. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/pb2/common_pb2.py +0 -0
  20. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/pb2/errors_pb2.py +0 -0
  21. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/pb2/keys_pb2.py +0 -0
  22. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/pb2/signatures_pb2.py +0 -0
  23. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/pb2/universal_message_pb2.py +0 -0
  24. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/pb2/vcsec_pb2.py +0 -0
  25. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/pb2/vehicle_pb2.py +0 -0
  26. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/ratecalculator.py +0 -0
  27. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/teslafleetoauth.py +0 -0
  28. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/teslafleetopensource.py +0 -0
  29. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/teslemetry.py +0 -0
  30. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/tessie.py +0 -0
  31. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/user.py +0 -0
  32. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/vehicle.py +0 -0
  33. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api/vehiclespecific.py +0 -0
  34. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api.egg-info/SOURCES.txt +0 -0
  35. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api.egg-info/dependency_links.txt +0 -0
  36. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api.egg-info/requires.txt +0 -0
  37. {tesla_fleet_api-0.8.1 → tesla_fleet_api-0.8.2}/tesla_fleet_api.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tesla_fleet_api
3
- Version: 0.8.1
3
+ Version: 0.8.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
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="tesla_fleet_api",
8
- version="0.8.1",
8
+ version="0.8.2",
9
9
  author="Brett Adams",
10
10
  author_email="hello@teslemetry.com",
11
11
  description="Tesla Fleet API library for Python",
@@ -3,7 +3,7 @@
3
3
  from enum import Enum
4
4
  import logging
5
5
 
6
- VERSION = "0.8.1"
6
+ VERSION = "0.8.2"
7
7
  LOGGER = logging.getLogger(__package__)
8
8
  SERVERS = {
9
9
  "na": "https://fleet-api.prd.na.vn.cloud.tesla.com",
@@ -4,11 +4,11 @@ from json import dumps
4
4
  from typing import Any, Awaitable
5
5
  from os.path import exists
6
6
  import aiohttp
7
+ import aiofiles
7
8
 
8
9
  # cryptography
9
- from cryptography.hazmat.primitives.ciphers.aead import AESGCM
10
10
  from cryptography.hazmat.primitives.asymmetric import ec
11
- from cryptography.hazmat.primitives import hashes, serialization
11
+ from cryptography.hazmat.primitives import serialization
12
12
  from cryptography.hazmat.backends import default_backend
13
13
 
14
14
  from .exceptions import raise_for_status, InvalidRegion, LibraryError, ResponseError
@@ -30,7 +30,7 @@ class TeslaFleetApi:
30
30
  session: aiohttp.ClientSession
31
31
  headers: dict[str, str]
32
32
  refresh_hook: Awaitable | None = None
33
- _private_key: ec.EllipticCurvePrivateKey
33
+ _private_key: ec.EllipticCurvePrivateKey | None = None
34
34
 
35
35
  def __init__(
36
36
  self,
@@ -161,8 +161,8 @@ class TeslaFleetApi:
161
161
  "api/1/products",
162
162
  )
163
163
 
164
- def private_key(self, path: str = "private_key.pem") -> ec.EllipticCurvePrivateKey:
165
- """Create or load the private key."""
164
+ async def get_private_key(self, path: str = "private_key.pem") -> ec.EllipticCurvePrivateKey:
165
+ """Get or create the private key."""
166
166
  if not exists(path):
167
167
  self._private_key = ec.generate_private_key(
168
168
  ec.SECP256R1(), default_backend()
@@ -173,16 +173,15 @@ class TeslaFleetApi:
173
173
  format=serialization.PrivateFormat.TraditionalOpenSSL,
174
174
  encryption_algorithm=serialization.NoEncryption(),
175
175
  )
176
- with open(path, "wb") as key_file:
177
- key_file.write(pem)
178
- return self._private_key
176
+ async with aiofiles.open(path, "wb") as key_file:
177
+ await key_file.write(pem)
179
178
  else:
180
179
  try:
181
- with open(path, "rb") as key_file:
182
- key_data = key_file.read()
183
- value = serialization.load_pem_private_key(
184
- key_data, password=None, backend=default_backend()
185
- )
180
+ async with aiofiles.open(path, "rb") as key_file:
181
+ key_data = await key_file.read()
182
+ value = serialization.load_pem_private_key(
183
+ key_data, password=None, backend=default_backend()
184
+ )
186
185
  except FileNotFoundError:
187
186
  raise FileNotFoundError(f"Private key file not found at {path}")
188
187
  except PermissionError:
@@ -191,4 +190,4 @@ class TeslaFleetApi:
191
190
  if not isinstance(value, ec.EllipticCurvePrivateKey):
192
191
  raise AssertionError("Loaded key is not an EllipticCurvePrivateKey")
193
192
  self._private_key = value
194
- return self._private_key
193
+ return self._private_key
@@ -1,6 +1,5 @@
1
1
  from __future__ import annotations
2
2
  import base64
3
- from dataclasses import dataclass
4
3
  from random import randbytes
5
4
  from typing import Any, TYPE_CHECKING
6
5
  import time
@@ -155,7 +154,7 @@ class Session:
155
154
  class VehicleSigned(VehicleSpecific):
156
155
  """Class describing the Tesla Fleet API vehicle endpoints and commands for a specific vehicle with command signing."""
157
156
 
158
- _key: ec.EllipticCurvePrivateKey
157
+ _private_key: ec.EllipticCurvePrivateKey
159
158
  _public_key: bytes
160
159
  _from_destination: bytes
161
160
  _sessions: dict[int, Session]
@@ -165,13 +164,13 @@ class VehicleSigned(VehicleSpecific):
165
164
  ):
166
165
  super().__init__(parent, vin)
167
166
  if key:
168
- self._key = key
167
+ self._private_key = key
169
168
  elif parent._parent._private_key:
170
- self._key = parent._parent._private_key
169
+ self._private_key = parent._parent._private_key
171
170
  else:
172
171
  raise ValueError("No private key.")
173
172
 
174
- self._public_key = self._key.public_key().public_bytes(
173
+ self._public_key = self._private_key.public_key().public_bytes(
175
174
  encoding=Encoding.X962, format=PublicFormat.UncompressedPoint
176
175
  )
177
176
  self._from_destination = randbytes(16)
@@ -201,7 +200,7 @@ class VehicleSigned(VehicleSpecific):
201
200
  vehicle_public_key = info.publicKey
202
201
 
203
202
  # Derive shared key from private key _key and vehicle public key
204
- shared = self._key.exchange(
203
+ shared = self._private_key.exchange(
205
204
  ec.ECDH(),
206
205
  ec.EllipticCurvePublicKey.from_encoded_point(
207
206
  ec.SECP256R1(), vehicle_public_key
@@ -215,8 +214,6 @@ class VehicleSigned(VehicleSpecific):
215
214
  delta=int(time.time()) - info.clock_time,
216
215
  )
217
216
 
218
- print(self._sessions[domain])
219
-
220
217
  async def _sendVehicleSecurity(self, command: UnsignedMessage) -> dict[str, Any]:
221
218
  """Sign and send a message to Infotainment computer."""
222
219
  if DOMAIN_VEHICLE_SECURITY not in self._sessions:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tesla_fleet_api
3
- Version: 0.8.1
3
+ Version: 0.8.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
File without changes