Skip to content

Commit d858609

Browse files
authored
Merge pull request #26 from Teslemetry/claude/teslemetry-api-endpoints-5bi2h
Add missing Teslemetry API endpoints
2 parents 23534a7 + f5d6029 commit d858609

File tree

3 files changed

+274
-0
lines changed

3 files changed

+274
-0
lines changed

docs/teslemetry.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,186 @@ async def main():
159159

160160
asyncio.run(main())
161161
```
162+
163+
## Get Streaming Fields
164+
165+
The `fields` method retrieves streaming field parameters and metadata.
166+
167+
```python
168+
async def main():
169+
async with aiohttp.ClientSession() as session:
170+
teslemetry = Teslemetry(
171+
session=session,
172+
access_token="<access_token>",
173+
)
174+
175+
response = await teslemetry.fields()
176+
print(response)
177+
178+
asyncio.run(main())
179+
```
180+
181+
## Get Vehicle Configuration
182+
183+
The `vehicle_config` method retrieves the saved vehicle configuration for a specific vehicle.
184+
185+
```python
186+
async def main():
187+
async with aiohttp.ClientSession() as session:
188+
teslemetry = Teslemetry(
189+
session=session,
190+
access_token="<access_token>",
191+
)
192+
193+
vin = "<vin>"
194+
195+
response = await teslemetry.vehicle_config(vin)
196+
print(response)
197+
198+
asyncio.run(main())
199+
```
200+
201+
## Get Streaming Configuration
202+
203+
The `streaming_config` method retrieves the streaming configuration for a specific vehicle, including certificate, hostname, port, and configurable telemetry fields.
204+
205+
```python
206+
async def main():
207+
async with aiohttp.ClientSession() as session:
208+
teslemetry = Teslemetry(
209+
session=session,
210+
access_token="<access_token>",
211+
)
212+
213+
vin = "<vin>"
214+
215+
response = await teslemetry.streaming_config(vin)
216+
print(response)
217+
218+
asyncio.run(main())
219+
```
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+
## Vehicle Custom Commands
304+
305+
### Clear PIN to Drive
306+
307+
The `clear_pin_to_drive` method deactivates PIN to Drive on the vehicle.
308+
309+
```python
310+
async def main():
311+
async with aiohttp.ClientSession() as session:
312+
teslemetry = Teslemetry(
313+
session=session,
314+
access_token="<access_token>",
315+
)
316+
317+
vehicle = teslemetry.vehicles.create("<vin>")
318+
319+
# Clear PIN to Drive with your 4-digit PIN
320+
response = await vehicle.clear_pin_to_drive("1234")
321+
print(response)
322+
323+
asyncio.run(main())
324+
```
325+
326+
### Remove All Impermanent Keys
327+
328+
The `remove_key` method removes all impermanent keys from the vehicle.
329+
330+
```python
331+
async def main():
332+
async with aiohttp.ClientSession() as session:
333+
teslemetry = Teslemetry(
334+
session=session,
335+
access_token="<access_token>",
336+
)
337+
338+
vehicle = teslemetry.vehicles.create("<vin>")
339+
340+
response = await vehicle.remove_key()
341+
print(response)
342+
343+
asyncio.run(main())
344+
```

tesla_fleet_api/teslemetry/teslemetry.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,75 @@ async def migrate_to_oauth(
122122
new_token["expires_in"] = int(new_token["expires_in"])
123123
new_token["expires_at"] = time() + new_token["expires_in"]
124124
return new_token
125+
126+
async def fields(self) -> dict[str, Any]:
127+
"""Get streaming field parameters and metadata."""
128+
return await self._request(
129+
Method.GET,
130+
"fields.json",
131+
)
132+
133+
async def vehicle_config(self, vin: str) -> dict[str, Any]:
134+
"""Get the saved vehicle configuration.
135+
136+
Args:
137+
vin: Vehicle identification number
138+
"""
139+
return await self._request(
140+
Method.GET,
141+
f"api/vehicle_config/{vin}",
142+
)
143+
144+
async def streaming_config(self, vin: str) -> dict[str, Any]:
145+
"""Get the streaming configuration for a specific vehicle.
146+
147+
Returns certificate, hostname, port, and configurable telemetry fields.
148+
149+
Args:
150+
vin: Vehicle identification number
151+
"""
152+
return await self._request(
153+
Method.GET,
154+
f"api/config/{vin}",
155+
)
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+
)

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)