This Python library is a tiny OpenADR3 library that can be used to perform a minimal set of operations towards a VTN.
Currently, it supports the following operations:
- List events
- Filter by program id
- Filter by target type and target values
- Limit and skip for pagination
- List reports
- Filter by program id
- Filter by event id
- Filter by client name
- Limit and skip for pagination
- Create a report from an event
A small example of how to list events and reports from a VTN:
import asyncio
import aiohttp
import toadr3
TOKEN_URL = "" # URL to the OAuth2 token endpoint
GRANT_TYPE = "" # OAuth2 grant type
SCOPE = "" # OAuth2 scope
CLIENT_ID = "" # OAuth2 client ID or set to None use environment variable
CLIENT_SECRET = "" # OAuth2 client secret or set to None use environment variable
VTN_URL = "" # URL to the VTN
async def main():
async with aiohttp.ClientSession(json_serialize=toadr3.toadr_json_serialize) as session:
token = await toadr3.acquire_access_token(
session, TOKEN_URL, GRANT_TYPE, SCOPE, CLIENT_ID, CLIENT_SECRET
)
events = await toadr3.get_events(session, VTN_URL, token)
for event in events:
print(f"Event ID: {event.id} - {event.event_name}")
reports = await toadr3.get_reports(session, VTN_URL, token)
for report in reports:
print(f"Report ID: {report.id} - {report.report_name}")
report = toadr3.create_report(
event=events[0],
client_name="client_name",
report_type="REPORT_TYPE",
report_values=[...],
)
result = await toadr3.post_report(session, VTN_URL, token, report)
if __name__ == '__main__':
asyncio.run(main())