Skip to content

Commit

Permalink
Updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
arvindrajan92 committed Jan 29, 2024
1 parent 38e5b47 commit 38b98e7
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pip install mindmelting.powerpal

## Usage

### Live data

```python
from aiohttp import ClientSession
from mindmelting.powerpal import Powerpal
Expand Down Expand Up @@ -43,6 +45,27 @@ async def get_powerpal_data(self):
except PowerpalException as exception:
# All other exceptions
...
```

### Historical time-series data

#### With no arguments

```python
from aiohttp import ClientSession
from mindmelting.powerpal import Powerpal
from mindmelting.powerpal.exceptions import (
PowerpalException,
PowerpalAuthorizationException,
PowerpalAuthenticationException
)

EXAMPLE_AUTH_KEY = 'xyz123' # Your Powerpal API authorization key
EXAMPLE_DEVICE_ID = 'abc123' # Your Powerpal device ID

session = ClientSession()

powerpal = Powerpal(session, EXAMPLE_AUTH_KEY, EXAMPLE_DEVICE_ID)

async def get_powerpal_time_series_data(self):
try:
Expand All @@ -58,3 +81,40 @@ async def get_powerpal_time_series_data(self):
# All other exceptions
...
```

#### With arguments

```python
from aiohttp import ClientSession
from mindmelting.powerpal import Powerpal
from mindmelting.powerpal.exceptions import (
PowerpalException,
PowerpalAuthorizationException,
PowerpalAuthenticationException
)

EXAMPLE_AUTH_KEY = 'xyz123' # Your Powerpal API authorization key
EXAMPLE_DEVICE_ID = 'abc123' # Your Powerpal device ID

session = ClientSession()

powerpal = Powerpal(session, EXAMPLE_AUTH_KEY, EXAMPLE_DEVICE_ID)

async def get_powerpal_time_series_data(self, start: int, end: int, sample: int):
try:
return await powerpal.get_time_series_data(
start=start, # unix timestamp of start time, e.g., 1706321820 for Sat Jan 27 2024 02:17:00 GMT+0000
end=end, # unix timestamp of end time, e.g., 1706332620 for Sat Jan 27 2024 05:17:00 GMT+0000
sample=sample # sample (in minutes) to "bucket" readings, e.g., 60 for 1 hour interval
)

except PowerpalAuthenticationException as exception:
# 401 - Authorization key is invalid
...
except PowerpalAuthorizationException as exception:
# 403 - Device Id is invalid
...
except PowerpalException as exception:
# All other exceptions
...
```

0 comments on commit 38b98e7

Please sign in to comment.