-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcustom_tool.py
More file actions
59 lines (50 loc) · 1.79 KB
/
custom_tool.py
File metadata and controls
59 lines (50 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from arcade.tools import tool, ToolContext
from arcade.auth import Tesla
import requests
from typing import Dict, Any, List
@tool(
name="get_vehicle_data",
description="Get data about the user's Tesla vehicles",
auth=Tesla(scopes=["vehicle_data"])
)
def get_vehicle_data(context: ToolContext) -> Dict[str, Any]:
"""
Get a list of vehicles associated with the user's Tesla account.
Returns:
A dictionary containing the vehicle data.
"""
# The token is automatically provided by the Arcade Engine
token = context.authorization.token
# Use the token to call the Tesla Fleet API
headers = {"Authorization": f"Bearer {token}"}
response = requests.get("https://fleet-api.prd.eu.vn.cloud.tesla.com/api/1/vehicles", headers=headers)
# Return the vehicle data
return response.json()
@tool(
name="send_vehicle_command",
description="Send a command to a Tesla vehicle",
auth=Tesla(scopes=["vehicle_cmds"])
)
def send_vehicle_command(
context: ToolContext,
vehicle_id: str,
command: str
) -> Dict[str, Any]:
"""
Send a command to a Tesla vehicle.
Args:
vehicle_id: The ID of the vehicle to send the command to.
command: The command to send (e.g., "wake_up", "door_unlock", "climate_on").
Returns:
A dictionary containing the response from the Tesla API.
"""
# The token is automatically provided by the Arcade Engine
token = context.authorization.token
# Use the token to call the Tesla Fleet API
headers = {"Authorization": f"Bearer {token}"}
response = requests.post(
f"https://fleet-api.prd.eu.vn.cloud.tesla.com/api/1/vehicles/{vehicle_id}/command/{command}",
headers=headers
)
# Return the response
return response.json()