Skip to content

Commit 73d0bd8

Browse files
committed
1 parent 666abe4 commit 73d0bd8

File tree

1 file changed

+47
-41
lines changed

1 file changed

+47
-41
lines changed

docs/bluetooth_vehicles.md

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Detailed Examples for Using Bluetooth for Vehicles
1+
# Bluetooth for Vehicles
22

3-
This document provides detailed examples for using the `TeslaBluetooth` class to interact with Tesla vehicles using Bluetooth.
3+
This document provides detailed examples for using Bluetooth for vehicles.
44

5-
## Example 1: Discovering Tesla Vehicles
5+
## Initialize TeslaBluetooth
66

7-
The following example demonstrates how to discover Tesla vehicles using Bluetooth:
7+
The `TeslaBluetooth` class provides methods to interact with Tesla vehicles using Bluetooth. Here's a basic example to initialize the `TeslaBluetooth` class and discover nearby Tesla vehicles:
88

99
```python
1010
import asyncio
@@ -21,72 +21,78 @@ async def main():
2121
asyncio.run(main())
2222
```
2323

24-
## Example 2: Querying Display Name
24+
## Create VehicleBluetooth Instance
2525

26-
The following example demonstrates how to query the display name of a Tesla vehicle using Bluetooth:
26+
You can create a `VehicleBluetooth` instance using the `TeslaBluetooth` class. Here's a basic example to create a `VehicleBluetooth` instance and set the private key from a file:
2727

2828
```python
2929
import asyncio
30-
from bleak import BleakScanner
3130
from tesla_fleet_api import TeslaBluetooth
3231

3332
async def main():
34-
scanner = BleakScanner()
35-
devices = await scanner.discover()
36-
for device in devices:
37-
if TeslaBluetooth().valid_name(device.name):
38-
print(f"Found Tesla vehicle: {device.name}")
39-
name = await TeslaBluetooth().query_display_name(device)
40-
print(f"Display name: {name}")
33+
tesla_bluetooth = TeslaBluetooth()
34+
tesla_bluetooth.get_private_key("path/to/private_key.pem")
35+
vehicle = tesla_bluetooth.vehicles.create("<vin>")
36+
vehicle.find_vehicle()
37+
print(f"Created VehicleBluetooth instance for VIN: {vehicle.vin}")
4138

4239
asyncio.run(main())
4340
```
4441

45-
## Example 3: Connecting to a Tesla Vehicle
42+
## Pair Vehicle
4643

47-
The following example demonstrates how to connect to a Tesla vehicle using Bluetooth:
44+
You can pair a `VehicleBluetooth` instance using the `pair` method. Here's a basic example to pair a `VehicleBluetooth` instance:
4845

4946
```python
5047
import asyncio
51-
from bleak import BleakScanner
5248
from tesla_fleet_api import TeslaBluetooth
5349

5450
async def main():
55-
scanner = BleakScanner()
56-
devices = await scanner.discover()
57-
for device in devices:
58-
if TeslaBluetooth().valid_name(device.name):
59-
print(f"Found Tesla vehicle: {device.name}")
60-
async with TeslaBluetooth() as bluetooth:
61-
await bluetooth.connect(device)
62-
print("Connected to Tesla vehicle")
51+
tesla_bluetooth = TeslaBluetooth()
52+
device = await tesla_bluetooth.find_vehicle()
53+
private_key = tesla_bluetooth.get_private_key("path/to/private_key.pem")
54+
vehicle = tesla_bluetooth.vehicles.create("<vin>")
55+
await vehicle.pair()
56+
print(f"Paired with VehicleBluetooth instance for VIN: {vehicle.vin}")
6357

6458
asyncio.run(main())
6559
```
6660

67-
## Example 4: Querying Vehicle Data
61+
## Wake Up Vehicle
6862

69-
The following example demonstrates how to query vehicle data from a Tesla vehicle using Bluetooth:
63+
You can wake up a `VehicleBluetooth` instance using the `wake_up` method. Here's a basic example to wake up a `VehicleBluetooth` instance:
64+
65+
```python
66+
import asyncio
67+
from tesla_fleet_api import TeslaBluetooth
68+
69+
async def main():
70+
tesla_bluetooth = TeslaBluetooth()
71+
device = await tesla_bluetooth.find_vehicle()
72+
private_key = tesla_bluetooth.get_private_key("path/to/private_key.pem")
73+
vehicle = tesla_bluetooth.vehicles.create("<vin>")
74+
await vehicle.wake_up()
75+
print(f"Woke up VehicleBluetooth instance for VIN: {vehicle.vin}")
76+
77+
asyncio.run(main())
78+
```
79+
80+
## Get Vehicle Data
81+
82+
You can get data from a `VehicleBluetooth` instance using the `vehicle_data` method. Here's a basic example to get data from a `VehicleBluetooth` instance:
7083

7184
```python
7285
import asyncio
73-
from bleak import BleakScanner
7486
from tesla_fleet_api import TeslaBluetooth, BluetoothVehicleData
7587

7688
async def main():
77-
scanner = BleakScanner()
78-
devices = await scanner.discover()
79-
for device in devices:
80-
if TeslaBluetooth().valid_name(device.name):
81-
print(f"Found Tesla vehicle: {device.name}")
82-
async with TeslaBluetooth() as bluetooth:
83-
await bluetooth.connect(device)
84-
data = await bluetooth.vehicle_data([
85-
BluetoothVehicleData.CHARGE_STATE,
86-
BluetoothVehicleData.CLIMATE_STATE,
87-
BluetoothVehicleData.DRIVE_STATE,
88-
])
89-
print(f"Vehicle data: {data}")
89+
tesla_bluetooth = TeslaBluetooth()
90+
device = await tesla_bluetooth.find_vehicle()
91+
private_key = tesla_bluetooth.get_private_key("path/to/private_key.pem")
92+
vehicle = tesla_bluetooth.vehicles.create("<vin>")
93+
data = await vehicle.vehicle_data([BluetoothVehicleData.CHARGE_STATE, BluetoothVehicleData.CLIMATE_STATE])
94+
print(f"Vehicle data for VIN: {vehicle.vin}")
95+
print(data)
9096

9197
asyncio.run(main())
9298
```

0 commit comments

Comments
 (0)