tesla-fleet-api 1.0.3__py3-none-any.whl → 1.0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tesla_fleet_api/const.py CHANGED
@@ -3,7 +3,7 @@
3
3
  from enum import Enum
4
4
  import logging
5
5
 
6
- VERSION = "1.0.3"
6
+ VERSION = "1.0.4"
7
7
  LOGGER = logging.getLogger(__package__)
8
8
  SERVERS = {
9
9
  "na": "https://fleet-api.prd.na.vn.cloud.tesla.com",
@@ -2,6 +2,7 @@
2
2
 
3
3
  import hashlib
4
4
  import re
5
+ from google.protobuf.json_format import MessageToJson, MessageToDict
5
6
  from bleak.backends.device import BLEDevice
6
7
  from cryptography.hazmat.primitives.asymmetric import ec
7
8
 
@@ -43,3 +44,11 @@ class Vehicles(dict[str, VehicleBluetooth]):
43
44
  vehicle = VehicleBluetooth(self._parent, vin, key, device)
44
45
  self[vin] = vehicle
45
46
  return vehicle
47
+
48
+ def toJson(message) -> str:
49
+ """Convert a protobuf message to JSON."""
50
+ return MessageToJson(message, preserving_proto_field_name=True)
51
+
52
+ def toDict(message) -> dict:
53
+ """Convert a protobuf message to a dictionary."""
54
+ return MessageToDict(message, preserving_proto_field_name=True)
@@ -4,7 +4,7 @@ import hashlib
4
4
  import asyncio
5
5
  from typing import TYPE_CHECKING
6
6
  from google.protobuf.message import DecodeError
7
-
7
+ from bleak_retry_connector import establish_connection, MAX_CONNECT_ATTEMPTS
8
8
  from bleak import BleakClient, BleakScanner
9
9
  from bleak.backends.characteristic import BleakGATTCharacteristic
10
10
  from bleak.backends.device import BLEDevice
@@ -19,17 +19,14 @@ from tesla_fleet_api.const import (
19
19
  BluetoothVehicleData
20
20
  )
21
21
  from tesla_fleet_api.exceptions import (
22
- MESSAGE_FAULTS,
23
22
  WHITELIST_OPERATION_STATUS,
24
23
  WhitelistOperationStatus,
25
- NotOnWhitelistFault,
26
24
  )
27
25
 
28
26
  # Protocol
29
27
  from tesla_fleet_api.tesla.vehicle.proto.car_server_pb2 import (
30
28
  Action,
31
29
  VehicleAction,
32
- Response,
33
30
  GetVehicleData,
34
31
  GetChargeState,
35
32
  GetClimateState,
@@ -44,10 +41,6 @@ from tesla_fleet_api.tesla.vehicle.proto.car_server_pb2 import (
44
41
  GetSoftwareUpdateState,
45
42
  GetParentalControlsState,
46
43
  )
47
- from tesla_fleet_api.tesla.vehicle.proto.signatures_pb2 import (
48
- SessionInfo,
49
- Session_Info_Status
50
- )
51
44
  from tesla_fleet_api.tesla.vehicle.proto.universal_message_pb2 import (
52
45
  Destination,
53
46
  Domain,
@@ -84,6 +77,7 @@ class VehicleBluetooth(Commands):
84
77
  """Class describing the Tesla Fleet API vehicle endpoints and commands for a specific vehicle with command signing."""
85
78
 
86
79
  ble_name: str
80
+ device: BLEDevice
87
81
  client: BleakClient
88
82
  _queues: dict[Domain, asyncio.Queue]
89
83
  _ekey: ec.EllipticCurvePublicKey
@@ -103,26 +97,28 @@ class VehicleBluetooth(Commands):
103
97
  if device is not None:
104
98
  self.client = BleakClient(device, services=[SERVICE_UUID])
105
99
 
106
- async def find_client(self, scanner: BleakScanner = BleakScanner()) -> BleakClient:
100
+ async def find_vehicle(self, name: str | None = None, address: str | None = None, scanner: BleakScanner = BleakScanner()) -> BLEDevice:
107
101
  """Find the Tesla BLE device."""
108
-
109
- device = await scanner.find_device_by_name(self.ble_name)
102
+ if name is not None:
103
+ device = await scanner.find_device_by_name(name)
104
+ elif address is not None:
105
+ device = await scanner.find_device_by_address(address)
106
+ else:
107
+ device = await scanner.find_device_by_name(self.ble_name)
110
108
  if not device:
111
109
  raise ValueError(f"Device {self.ble_name} not found")
112
- self.client = BleakClient(device, services=[SERVICE_UUID])
113
- LOGGER.debug(f"Discovered device {device.name} {device.address}")
114
- return self.client
110
+ self.device = device
111
+ return self.device
112
+
113
+ def set_device(self, device: BLEDevice) -> None:
114
+ self.device = device
115
115
 
116
- def create_client(self, device: str|BLEDevice) -> BleakClient:
117
- """Create a client using a MAC address or Bleak Device."""
118
- self.client = BleakClient(device, services=[SERVICE_UUID])
119
- return self.client
116
+ def get_device(self) -> BLEDevice:
117
+ return self.device
120
118
 
121
- async def connect(self, device: str|BLEDevice | None = None) -> None:
119
+ async def connect(self, device: BLEDevice | None = None, max_attempts: int = MAX_CONNECT_ATTEMPTS) -> None:
122
120
  """Connect to the Tesla BLE device."""
123
- if device is not None:
124
- self.create_client(device)
125
- await self.client.connect()
121
+ self.client = await establish_connection(BleakClient, self.device, self.vin, max_attempts=max_attempts, ble_device_callback=self.get_device)
126
122
  await self.client.start_notify(READ_UUID, self._on_notify)
127
123
 
128
124
  async def disconnect(self) -> bool:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tesla_fleet_api
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Summary: Tesla Fleet API library for Python
5
5
  Home-page: https://github.com/Teslemetry/python-tesla-fleet-api
6
6
  Author: Brett Adams
@@ -18,6 +18,7 @@ Requires-Dist: aiolimiter
18
18
  Requires-Dist: cryptography
19
19
  Requires-Dist: protobuf
20
20
  Requires-Dist: bleak
21
+ Requires-Dist: bleak-retry-connector
21
22
  Dynamic: author
22
23
  Dynamic: author-email
23
24
  Dynamic: classifier
@@ -29,10 +30,11 @@ Dynamic: requires-python
29
30
  Dynamic: summary
30
31
 
31
32
  # Tesla Fleet Api
32
- Python library for Tesla Fleet API and Teslemetry.
33
+ Python library for Tesla Fleet API and Tesla Command Protocol, including signed commands and encrypted local Bluetooth (BLE). Also provides interfaces for Teslemetry and Tessie.
33
34
 
34
- Based on [Tesla Developer documentation](https://developer.tesla.com/docs/fleet-api).
35
+ Based on [Tesla Developer documentation](https://developer.tesla.com/docs/fleet-api) and [Tesla Command Protocol](https://github.com/teslamotors/vehicle-command/blob/main/pkg/protocol/protocol.md)
35
36
 
37
+ **Documentation is currently outdated for V1.0.X**
36
38
 
37
39
  ## TeslaFleetApi
38
40
  This is the base class, however can also be used directly if you have a valid user access_token.
@@ -1,9 +1,9 @@
1
1
  tesla_fleet_api/__init__.py,sha256=3DZMoZ-5srW-7SooAjqcRubQDuZPY8rMKH7eqIp4qtg,392
2
- tesla_fleet_api/const.py,sha256=RB2ZgI0_y0DkLUJtMSpklCRH9aNlrninO4zot5cA-H0,3748
2
+ tesla_fleet_api/const.py,sha256=HK5PibaarH3CjrtN2Ma-xytZyhkpTdlbQ8rpVbL9DDo,3748
3
3
  tesla_fleet_api/exceptions.py,sha256=1EkMnDxQYxZBn4ApjGodIBZyNPu9oa_Pgpdl6lQQ5gk,35523
4
4
  tesla_fleet_api/ratecalculator.py,sha256=4lz8yruUeouHXh_3ezsXX-CTpIegp1T1J4VuRV_qdHA,1791
5
5
  tesla_fleet_api/tesla/__init__.py,sha256=Cvpqu8OaOFmbuwu9KjgYrje8eVluDp2IU_zwdtXbmO0,282
6
- tesla_fleet_api/tesla/bluetooth.py,sha256=UCKXF3u_TfuGlJ-LYEIxgmbbzlElZfuJOInsWJ_ltr0,1471
6
+ tesla_fleet_api/tesla/bluetooth.py,sha256=WhDo66OEwCGhvsGskvWcGUiNv6eyFsdEiQdIm571jQM,1835
7
7
  tesla_fleet_api/tesla/charging.py,sha256=D7I7cAf-3-95sIjyP6wpVqCq9Cppj6U-VPFQGpQQ8bs,1704
8
8
  tesla_fleet_api/tesla/energysite.py,sha256=96Q5npsJ2YIa257o_NL5_3gJNUS-ioAL7sTeQeGPgAM,6110
9
9
  tesla_fleet_api/tesla/fleet.py,sha256=X74tzwGO9w65j9YUGuW04CwG7Bx6biEHwxIjWGCzB4c,5670
@@ -12,7 +12,7 @@ tesla_fleet_api/tesla/partner.py,sha256=e-l6sEP6-IupjFEQieSUjhhvRXF3aL4ebPNahcGF
12
12
  tesla_fleet_api/tesla/tesla.py,sha256=Jlz90-fM0nJbhnQN0k3ukNv59-9KqZZbyQ91IiLIbfo,2010
13
13
  tesla_fleet_api/tesla/user.py,sha256=w8rwiAOIFjuDus8M0RpZ0wucJtw8kYFKtJfYVk7Ekr0,1194
14
14
  tesla_fleet_api/tesla/vehicle/__init__.py,sha256=3A5_wTQHofRShof4pUNOtF78-7lUh62uz2jq2ecnmRY,381
15
- tesla_fleet_api/tesla/vehicle/bluetooth.py,sha256=fhV24gni_tkhRJmK5I-xUX0dqxEw_lumRViEwmkXDSw,15665
15
+ tesla_fleet_api/tesla/vehicle/bluetooth.py,sha256=tEbuUMjG3PfDLc1s1ACg-3zdnF-lSwDsH1U5tg5qbRI,15746
16
16
  tesla_fleet_api/tesla/vehicle/commands.py,sha256=zgfc2yo1UxEh8ePqSb-4h0UTK0RmpCG_9LZX44CES2c,51268
17
17
  tesla_fleet_api/tesla/vehicle/fleet.py,sha256=K9BVZj6CChJSDSMFroa7Cz0KrsYWj32ILtQumarkLaU,32080
18
18
  tesla_fleet_api/tesla/vehicle/signed.py,sha256=ggdtq8PydKoCk044L5b2262nfNzZqPBnsJ4SonTFbb4,1539
@@ -44,8 +44,8 @@ tesla_fleet_api/teslemetry/vehicle.py,sha256=9_2N1iNNDouqfb6YBBWAFjnlzVRTf5frhXi
44
44
  tesla_fleet_api/tessie/__init__.py,sha256=9lhQJaB6X4PObUL9QdaaZYqs2BxiTidu3zmHcBESLVw,78
45
45
  tesla_fleet_api/tessie/tessie.py,sha256=qdMZ61TcQi5JRuv2qaxuLHtOuy8WZJ1WNqWg5WDAwwU,2615
46
46
  tesla_fleet_api/tessie/vehicle.py,sha256=9khv4oCkGGLxHzQ2FYhDPH7wczxEDiUppsDXalawarE,1125
47
- tesla_fleet_api-1.0.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
48
- tesla_fleet_api-1.0.3.dist-info/METADATA,sha256=ARBm4GR744Ru7F2JumVFrw4UgeSxnYeV1k25KlzgqhY,4056
49
- tesla_fleet_api-1.0.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
50
- tesla_fleet_api-1.0.3.dist-info/top_level.txt,sha256=jeNbog_1saXBFrGpom9WyPWmilxsyP3szL_G7JLWQfM,16
51
- tesla_fleet_api-1.0.3.dist-info/RECORD,,
47
+ tesla_fleet_api-1.0.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
48
+ tesla_fleet_api-1.0.4.dist-info/METADATA,sha256=KxQg4FAxCoWBheKhRSo104TIDTtcswTz-LhgFN7UAUo,4382
49
+ tesla_fleet_api-1.0.4.dist-info/WHEEL,sha256=nn6H5-ilmfVryoAQl3ZQ2l8SH5imPWFpm1A5FgEuFV4,91
50
+ tesla_fleet_api-1.0.4.dist-info/top_level.txt,sha256=jeNbog_1saXBFrGpom9WyPWmilxsyP3szL_G7JLWQfM,16
51
+ tesla_fleet_api-1.0.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (75.8.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5