Simple Python client for calling Powerpal Readings API.
Project description
powerpal
This repository and package is not affiliated with Powerpal.
Simple Python package for making calls to the Powerpal Readings API.
Credit to forfuncsake for the go client which this is influenced from: https://github.com/forfuncsake/powerpal
Installation
pip install mindmelting.powerpal
Usage
Live data
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_data(self):
try:
return await powerpal.get_data()
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
...
Historical time-series data
With no arguments
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:
return await powerpal.get_time_series_data()
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
...
With arguments
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
...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for mindmelting.powerpal-0.4.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4fd632b32a9f09d08965fea963d7ebcb64100e1a7543a6071470d62e5ec4cff |
|
MD5 | a1db24125dc0595b77d6aa67a3797887 |
|
BLAKE2b-256 | 1db18767c684b4e45d7a4c134f8fe887e4eb285842f2c7e1bab5d23ac95de52e |
Close
Hashes for mindmelting.powerpal-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46cee6e54c92aefe064ec8e681c916ba16854231c9ebfec9c5f9dc026338604c |
|
MD5 | 86eda8220da99d36cab32ffceaac168a |
|
BLAKE2b-256 | 338caa1eb045de4f43cefe9b43b193b92aaf7e941b494729c39ee0569efc6aec |