You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,41 @@ asyncio.run(main())
37
37
## TeslaFleetOAuth
38
38
This extends TeslaFleetApi to support OAuth, and requires a client_id, and either a refresh_token or initial authentication code.
39
39
40
+
```
41
+
import json
42
+
43
+
async def main():
44
+
with open("auth.json", "r") as f:
45
+
auth = json.load(f)
46
+
async with aiohttp.ClientSession() as session:
47
+
api = TeslaFleetOAuth(
48
+
session,
49
+
client_id=<client_id>,
50
+
access_token=auth["access_token"],
51
+
refresh_token=auth["refresh_token"],
52
+
expires=auth["expires"],
53
+
region="na",
54
+
raise_for_status=True,
55
+
)
56
+
try:
57
+
data = await api.vehicle.list()
58
+
print(data)
59
+
except TeslaFleetError.Base as e:
60
+
print(e.message, e.error)
61
+
62
+
with open("auth.json", "w") as f:
63
+
json.dump(
64
+
{
65
+
"access_token": api.access_token,
66
+
"refresh_token": api.refresh_token,
67
+
"expires": api.expires,
68
+
},
69
+
f,
70
+
)
71
+
72
+
asyncio.run(main())
73
+
```
74
+
40
75
## Teslemetry
41
76
This extends TeslaFleetApi to send requests through Teslemetry, which manages all aspects of Tesla OAuth. This class only requires an access_token from the Teslemetry console.
0 commit comments