Skip to content

Commit ee5eae9

Browse files
committed
Add remaining Teslemetry API endpoints from OpenAPI schema
Added missing Teslemetry-specific endpoints: Main Teslemetry class (teslemetry.py): - vehicle_image(vin): GET /api/image/{vin} - redirect to Tesla Design Studio vehicle image - stop_streaming(vin): DELETE /api/config/{vin} - stop streaming data from vehicle - modify_streaming_config(vin, fields): PATCH /api/config/{vin} - modify streaming configuration - create_streaming_config(vin, fields): POST /api/config/{vin} - create/update streaming configuration TeslemetryVehicle custom commands (vehicles.py): - clear_pin_to_drive(pin): POST /api/1/vehicles/{vin}/custom_command/clear_pin_to_drive - deactivate PIN to Drive - remove_key(): POST /api/1/vehicles/{vin}/custom_command/remove_key - remove all impermanent keys Updated documentation with examples for all new endpoints. All endpoints verified against https://api.teslemetry.com/openapi.yaml
1 parent 6022dc3 commit ee5eae9

File tree

3 files changed

+216
-0
lines changed

3 files changed

+216
-0
lines changed

docs/teslemetry.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,148 @@ async def main():
217217

218218
asyncio.run(main())
219219
```
220+
221+
## Stop Streaming
222+
223+
The `stop_streaming` method stops streaming data from a specific vehicle.
224+
225+
```python
226+
async def main():
227+
async with aiohttp.ClientSession() as session:
228+
teslemetry = Teslemetry(
229+
session=session,
230+
access_token="<access_token>",
231+
)
232+
233+
vin = "<vin>"
234+
235+
response = await teslemetry.stop_streaming(vin)
236+
print(response)
237+
238+
asyncio.run(main())
239+
```
240+
241+
## Modify Streaming Configuration
242+
243+
The `modify_streaming_config` method modifies the streaming configuration for a specific vehicle.
244+
245+
```python
246+
async def main():
247+
async with aiohttp.ClientSession() as session:
248+
teslemetry = Teslemetry(
249+
session=session,
250+
access_token="<access_token>",
251+
)
252+
253+
vin = "<vin>"
254+
255+
# Configure specific fields to stream
256+
fields = {
257+
"BatteryLevel": {
258+
"interval_seconds": 60,
259+
"minimum_delta": 0.1
260+
},
261+
"VehicleSpeed": {
262+
"interval_seconds": 30,
263+
"minimum_delta": 0.5
264+
}
265+
}
266+
267+
response = await teslemetry.modify_streaming_config(vin, fields)
268+
print(response)
269+
270+
asyncio.run(main())
271+
```
272+
273+
## Create Streaming Configuration
274+
275+
The `create_streaming_config` method creates or updates the streaming configuration for a specific vehicle.
276+
277+
```python
278+
async def main():
279+
async with aiohttp.ClientSession() as session:
280+
teslemetry = Teslemetry(
281+
session=session,
282+
access_token="<access_token>",
283+
)
284+
285+
vin = "<vin>"
286+
287+
# Configure fields to stream
288+
fields = {
289+
"BatteryLevel": {
290+
"interval_seconds": 60
291+
},
292+
"Location": {
293+
"interval_seconds": 120
294+
}
295+
}
296+
297+
response = await teslemetry.create_streaming_config(vin, fields)
298+
print(response)
299+
300+
asyncio.run(main())
301+
```
302+
303+
## Get Vehicle Image
304+
305+
The `vehicle_image` method gets the redirect URL to the Tesla Design Studio image of the vehicle.
306+
307+
```python
308+
async def main():
309+
async with aiohttp.ClientSession() as session:
310+
teslemetry = Teslemetry(
311+
session=session,
312+
access_token="<access_token>",
313+
)
314+
315+
vin = "<vin>"
316+
317+
response = await teslemetry.vehicle_image(vin)
318+
print(response)
319+
320+
asyncio.run(main())
321+
```
322+
323+
## Vehicle Custom Commands
324+
325+
### Clear PIN to Drive
326+
327+
The `clear_pin_to_drive` method deactivates PIN to Drive on the vehicle.
328+
329+
```python
330+
async def main():
331+
async with aiohttp.ClientSession() as session:
332+
teslemetry = Teslemetry(
333+
session=session,
334+
access_token="<access_token>",
335+
)
336+
337+
vehicle = teslemetry.vehicles.create("<vin>")
338+
339+
# Clear PIN to Drive with your 4-digit PIN
340+
response = await vehicle.clear_pin_to_drive("1234")
341+
print(response)
342+
343+
asyncio.run(main())
344+
```
345+
346+
### Remove All Impermanent Keys
347+
348+
The `remove_key` method removes all impermanent keys from the vehicle.
349+
350+
```python
351+
async def main():
352+
async with aiohttp.ClientSession() as session:
353+
teslemetry = Teslemetry(
354+
session=session,
355+
access_token="<access_token>",
356+
)
357+
358+
vehicle = teslemetry.vehicles.create("<vin>")
359+
360+
response = await vehicle.remove_key()
361+
print(response)
362+
363+
asyncio.run(main())
364+
```

tesla_fleet_api/teslemetry/teslemetry.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,55 @@ async def streaming_config(self, vin: str) -> dict[str, Any]:
153153
Method.GET,
154154
f"api/config/{vin}",
155155
)
156+
157+
async def stop_streaming(self, vin: str) -> dict[str, Any]:
158+
"""Stop streaming data from a specific vehicle.
159+
160+
Args:
161+
vin: Vehicle identification number
162+
"""
163+
return await self._request(
164+
Method.DELETE,
165+
f"api/config/{vin}",
166+
)
167+
168+
async def modify_streaming_config(
169+
self, vin: str, fields: dict[str, Any]
170+
) -> dict[str, Any]:
171+
"""Modify the streaming configuration for a specific vehicle.
172+
173+
Args:
174+
vin: Vehicle identification number
175+
fields: Fields to stream with their configuration
176+
"""
177+
return await self._request(
178+
Method.PATCH,
179+
f"api/config/{vin}",
180+
json={"fields": fields},
181+
)
182+
183+
async def create_streaming_config(
184+
self, vin: str, fields: dict[str, Any]
185+
) -> dict[str, Any]:
186+
"""Create/update the streaming configuration for a specific vehicle.
187+
188+
Args:
189+
vin: Vehicle identification number
190+
fields: Fields to stream with their configuration
191+
"""
192+
return await self._request(
193+
Method.POST,
194+
f"api/config/{vin}",
195+
json={"fields": fields},
196+
)
197+
198+
async def vehicle_image(self, vin: str) -> dict[str, Any]:
199+
"""Get redirect URL to Tesla Design Studio image of the vehicle.
200+
201+
Args:
202+
vin: Vehicle identification number
203+
"""
204+
return await self._request(
205+
Method.GET,
206+
f"api/image/{vin}",
207+
)

tesla_fleet_api/teslemetry/vehicles.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,25 @@ async def start_light_show(
260260
json=data,
261261
)
262262

263+
async def clear_pin_to_drive(self, pin: str) -> dict[str, Any]:
264+
"""Deactivates PIN to Drive.
265+
266+
Args:
267+
pin: 4-digit PIN to clear
268+
"""
269+
return await self._request(
270+
Method.POST,
271+
f"api/1/vehicles/{self.vin}/custom_command/clear_pin_to_drive",
272+
json={"pin": pin},
273+
)
274+
275+
async def remove_key(self) -> dict[str, Any]:
276+
"""Remove all impermanent keys from the vehicle."""
277+
return await self._request(
278+
Method.POST,
279+
f"api/1/vehicles/{self.vin}/custom_command/remove_key",
280+
)
281+
263282

264283
class TeslemetryVehicles(Vehicles):
265284
"""Class containing and creating vehicles."""

0 commit comments

Comments
 (0)