Package: herolabsapi
HeroLabsAPI: a Python3, asyncio-friendly library for Sonic Smart ValvesWritten by@markvaderherolabsapiis a Python 3,asyncio-friendly library for interacting withSonic by Hero Labs.Manufacturer DocumentationHero Labs API DocumentationHero Labs API Swagger UIA list of gathered API endpoints and their functions can be foundhereInstallationpip install herolabsapiUsage & ExamplesSee examples/example.py for full example codeimportasynciofromdatetimeimportdatetimefromherolabsapiimportClientasyncdefmain()->None:client=awaitClient.async_login("<EMAIL>","<PASSWORD>")# USER API CALLS# Get User Account Information:user_info=awaitclient.user.async_get_user_details()print(user_info)# SONIC DEVICE API CALLS# Get Sonic Devices Informationsonic_data=awaitclient.sonic.async_get_all_sonic_details()first_device_id=sonic_data["data"][0]["id"]# Get Sonic Device Informationdevice_info=awaitclient.sonic.async_get_sonic_details(first_device_id)print(device_info)print("Valve State:",device_info["valve_state"])# Get Device Telemetry Datadevice_telemetry=awaitclient.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 formattimestamp=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 numbertotal_sonics=awaitclient.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 Incidentsincidents=awaitclient.incidents.async_get_incidents()print("all incidents:",incidents)# Get Open Incidentsopen_incidents=awaitclient.incidents.async_get_open_incidents()print("open incidents:",open_incidents)# Get Incident Detailsincident_details=awaitclient.incidents.async_get_incident_details(demo_incident_id)print("details of specific incident:",incident_details)# Get Incidents by Property IDproperty_incidents=awaitclient.incidents.async_get_incidents_by_property(demo_property_id)print("all incidents for a property:",property_incidents)# Get Open Incidents by Property IDproperty_open_incidents=awaitclient.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), anaiohttpClientSessioncan be used for connection
pooling:importasynciofromaiohttpimportClientSessionfromdatetimeimportdatetimefromherolabsapiimportClientasyncdefmain()->None:"""Create the aiohttp session and run the example."""asyncwithClientSession()assession:client=awaitClient.async_login("<EMAIL>","<PASSWORD>",session=session)# USER API CALLS# Get User Account Information:user_info=awaitclient.user.async_get_user_details()#additional example code same as above and example folder