-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update README and provide example usage script
- Loading branch information
1 parent
7bbcfac
commit 43c3fa4
Showing
2 changed files
with
94 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,54 +34,18 @@ Method | Description | |
|
||
### Example | ||
|
||
The below walks through a common scenario: | ||
Included in the project is `example.py` which walks through a common scenario: | ||
|
||
1. Get all pods | ||
1. Get firmware and serial number data for one pod | ||
1. Updating the schedule of an individual pod | ||
1. Confirm that it worked | ||
1. Get information from the last charge | ||
|
||
> `PodPointClient` is async by default so the below example assumes you are running it within an async function. | ||
> You must provide your email address and password to the script as detailed below: | ||
```python | ||
from podpointclient import PodPointClient | ||
|
||
# Create a client | ||
client = PodPointClient(username="[email protected]", password="passw0rd!1") | ||
|
||
# Verify credentials work | ||
verified = await client.async_credentials_verified() | ||
print(verified) | ||
|
||
# Get user information | ||
user = await client.async_get_user() | ||
print(f"Account balance {user.account.balance}p") | ||
|
||
# Get all pods for a user | ||
pods = await client.async_get_all_pods() | ||
|
||
# Select one to update schedules for | ||
pod = pods[0] | ||
|
||
# Get firmware information for the pod | ||
firmwares = await client.async_get_firmware(pod=pod) | ||
firmware = firmwares[0] | ||
print(firmware.serial_number) | ||
print(firmware.update_available) | ||
|
||
# Update schedule to disabled (allow charging at any time) | ||
await client.async_set_schedule(enabled=False, pod=pod) | ||
|
||
# Get just that pod | ||
pod = await client.async_get_pod(pod_id=pod.id) | ||
# Check if the schedule is disabled | ||
schedule_status = pod.charge_schedules[0].is_active | ||
print(schedule_status) | ||
|
||
# Print last charge energy use | ||
charges = await client.async_get_charges(perpage=1, page=1) | ||
energy_used = charges[0].kwh_used | ||
print(energy_used) | ||
```bash | ||
python3 example.py --email PODPOINTEMAIL --password PODPOINTPASSWORD | ||
``` | ||
|
||
### Setting charging schedules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from podpointclient.client import PodPointClient | ||
import asyncio | ||
import aiohttp | ||
|
||
|
||
async def main(username: str, password: str, http_debug: bool = False, loop=None): | ||
# Create a session | ||
session = aiohttp.ClientSession(loop=loop) | ||
|
||
print(f"Logging into Pod Point with email: {username}") | ||
|
||
# Create a client | ||
client = PodPointClient( | ||
username=username, | ||
password=password, | ||
session=session, | ||
http_debug=http_debug | ||
) | ||
|
||
# Verify credentials work | ||
verified = await client.async_credentials_verified() | ||
print(f" Credentials verified: {verified}") | ||
|
||
print("Getting user details") | ||
# Get user information | ||
user = await client.async_get_user() | ||
print(f" Account balance {user.account.balance}p") | ||
|
||
print("Getting pods") | ||
# Get all pods for a user | ||
pods = await client.async_get_all_pods() | ||
print(f" Found {len(pods)} pod(s).") | ||
|
||
# Select one to update schedules for | ||
pod = pods[0] | ||
print(f"Selecting first pod: {pod.ppid}") | ||
|
||
# Get firmware information for the pod | ||
firmwares = await client.async_get_firmware(pod=pod) | ||
firmware = firmwares[0] | ||
print(f"Gettnig firmware data for {pod.ppid}") | ||
print(f" Serial: {firmware.serial_number}") | ||
print(f" Update available: {firmware.update_available}") | ||
|
||
print(f"Enabling charging for {pod.ppid}") | ||
# Update schedule to disabled (allow charging at any time) | ||
await client.async_set_schedule(enabled=False, pod=pod) | ||
|
||
# Get just that pod | ||
pod = await client.async_get_pod(pod_id=pod.id) | ||
# Check if the schedule is disabled | ||
schedule_status = pod.charge_schedules[0].is_active | ||
print(f" Schedule active: {schedule_status}") | ||
|
||
# Print last charge energy use | ||
print(f"Getting last charge for pod {pod.ppid}") | ||
charges = await client.async_get_charges(perpage=1, page=1) | ||
energy_used = charges[0].kwh_used | ||
print(f" kW charged: {energy_used}") | ||
|
||
if __name__ == "__main__": | ||
import time | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description="Run the example provided in the Readme to verify functionality.", | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
parser.add_argument("-e", "--email", type=str, help="Pod Point email") | ||
parser.add_argument("-p", "--password", type=str, help="Pod Point password") | ||
parser.add_argument("-d", "--debug", action="store_true", help="Enable HTTP debugging") | ||
args = parser.parse_args() | ||
config = vars(args) | ||
|
||
print("-- Pod Point client test script --") | ||
|
||
start = time.perf_counter() | ||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete( | ||
main( | ||
username=config['email'], | ||
password=config['password'], | ||
http_debug=config['debug'], | ||
loop=loop | ||
) | ||
) | ||
loop.close() | ||
|
||
print("") | ||
elapsed = time.perf_counter() - start | ||
print(f"Script executed in {elapsed:0.2f} seconds") |