HeroLabsAPI: a Python3, asyncio-friendly library for Sonic Smart Valves
Written by @markvader
herolabsapi is a Python 3, asyncio-friendly library for interacting with
Sonic by Hero Labs.
Manufacturer Documentation
A list of gathered API endpoints and their functions can be found here
Installation
pip install herolabsapi
Usage & Examples
See examples/example.py for full example code
import asyncio
from datetime import datetime
from herolabsapi import Client
async def main() -> None:
client = await Client.async_login("<EMAIL>", "<PASSWORD>")
# USER API CALLS
# Get User Account Information:
user_info = await client.user.async_get_user_details()
print(user_info)
# SONIC DEVICE API CALLS
# Get Sonic Devices Information
sonic_data = await client.sonic.async_get_all_sonic_details()
first_device_id = sonic_data["data"][0]["id"]
# Get Sonic Device Information
device_info = await client.sonic.async_get_sonic_details(first_device_id)
print(device_info)
print("Valve State:", device_info["valve_state"])
# Get Device Telemetry Data
device_telemetry = await client.sonic.async_sonic_telemetry_by_id(first_device_id)
print(device_telemetry)
print("Water Pressure:", device_telemetry["pressure"])
print("Water Flow:", device_telemetry["water_flow"])
print("Water Temperature:", device_telemetry["water_temp"])
# Convert timestamp to readable datetime format
timestamp = device_telemetry["probed_at"]
datetime_telemetry = datetime.fromtimestamp(timestamp).strftime('%H:%M:%S %d-%m-%y')
print("Telemetry timestamp:", datetime_telemetry)
# Get Total Sonic Devices number
total_sonics = await client.sonic.async_get_total_sonics()
print("Total Sonic Devices:", total_sonics)
# Rename Sonic Device
# await client.sonic.async_update_sonic_name(first_device_id, "New Sonic Name")
# Change Valve State
# Open the shutoff valve
# await client.sonic.async_open_sonic_valve(first_device_id)
# Close the shutoff valve
# await client.sonic.async_close_sonic_valve(first_device_id)
# INCIDENTS API CALLS
# Get Incidents
incidents = await client.incidents.async_get_incidents()
print("all incidents:", incidents)
# Get Open Incidents
open_incidents = await client.incidents.async_get_open_incidents()
print("open incidents:", open_incidents)
# Get Incident Details
incident_details = await client.incidents.async_get_incident_details(demo_incident_id)
print("details of specific incident:", incident_details)
# Get Incidents by Property ID
property_incidents = await client.incidents.async_get_incidents_by_property(demo_property_id)
print("all incidents for a property:", property_incidents)
# Get Open Incidents by Property ID
property_open_incidents = await client.incidents.async_get_open_incidents_by_property(demo_property_id)
print("open incidents for a property:", property_open_incidents)
# Action an Incident
# close_incident = await client.incidents.async_close_incident(demo_incident_id)
# print(close_incident)
# reopen_incident = await client.incidents.async_close_incident(demo_incident_id)
# There are additional api endpoints that can be explored and called (properties, signals, user),
# example code is in the examples folder.
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
By default, the library creates a new connection to Sonic Device with each coroutine. If you are
calling a large number of coroutines (or merely want to squeeze out every second of
runtime savings possible), an
aiohttp ClientSession can be used for connection
pooling:
import asyncio
from aiohttp import ClientSession
from datetime import datetime
from herolabsapi import Client
async def main() -> None:
"""Create the aiohttp session and run the example."""
async with ClientSession() as session:
client = await Client.async_login("<EMAIL>", "<PASSWORD>", session=session)
# USER API CALLS
# Get User Account Information:
user_info = await client.user.async_get_user_details()
#additional example code same as above and example folder
Metadata
Release files for herolabsapi 0.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| herolabsapi-0.5.1.tar.gz | 10.7 kB | Without provenance | Details for herolabsapi-0.5.1.tar.gz |
Release files / herolabsapi-0.5.1.tar.gz
| Download URL | herolabsapi-0.5.1.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c1d7ca8f99a81a05f692cdb5251cd73db5bc8c569116db5dcb63bae7373faafa
|
|
BLAKE2b-256 checksum How to use checksums |
c38018ec855aec4e7036b04d3b65ea23c6f50eafcc55fc11f526daee208d1244
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|
Security for herolabsapi 0.5.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.