Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 authored Jan 7, 2024
1 parent 9e608df commit 18c1474
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
# Teslemetry Stream Library
This is an asynchronous python library that connects to the Teslemetry Stream server and provides Tesla Fleet Telemetry over server side events.

## Installation

`pip install teslemetry-stream`

## Usage

The TeslemetryStream class requires:

- session: an aiohttp.ClientSession
- access_token: an access token from the (Teslemetry console)[https://teslemetry.com/console]
- vin: your Tesla's Vehicle Identification Number

The TeslemetryStream instance can then be configured with:
- `add_field(field, interval)`
- `remove_field(field)`
- `add_alert(alert)`
- `remove_alert(alert)`

The full list of possible values are provided in `TeslemetryStream.Fields` and `TeslemetryStream.Alerts`

To connect, either use `async with` on the instance, call `connect()`, or register an async callback on `listen()`, which will connect automatically.

Using `connect()` or `listen()` will require you to close the session manually using `close()`.

## Example
The following example puts the listening loop in the background, then stopping after 20 seconds.
```
async def main():
async with aiohttp.ClientSession() as session:
stream = TeslemetryStream(
token="<token>",
access_token="<token>",
vin="<vin>",
session=session,
)
await stream.connect()
print("Connected")
async def callback(event):
print(event)
asyncio.create_task(self.listen(callback))
asyncio.create_task(stream.listen(callback))
await asyncio.sleep(20)
await stream.close()
Expand Down

0 comments on commit 18c1474

Please sign in to comment.