Skip to content

Commit

Permalink
Add OAuth documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Jan 8, 2024
1 parent c2f1373 commit 7883360
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,41 @@ asyncio.run(main())
## TeslaFleetOAuth
This extends TeslaFleetApi to support OAuth, and requires a client_id, and either a refresh_token or initial authentication code.

```
import json
async def main():
with open("auth.json", "r") as f:
auth = json.load(f)
async with aiohttp.ClientSession() as session:
api = TeslaFleetOAuth(
session,
client_id=<client_id>,
access_token=auth["access_token"],
refresh_token=auth["refresh_token"],
expires=auth["expires"],
region="na",
raise_for_status=True,
)
try:
data = await api.vehicle.list()
print(data)
except TeslaFleetError.Base as e:
print(e.message, e.error)
with open("auth.json", "w") as f:
json.dump(
{
"access_token": api.access_token,
"refresh_token": api.refresh_token,
"expires": api.expires,
},
f,
)
asyncio.run(main())
```

## Teslemetry
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.

Expand Down

0 comments on commit 7883360

Please sign in to comment.