Python helper library for Hydros aquarium controller
Project description
PyHydros
Python helper library for authenticating against Hydros via AWS Cognito, calling the REST API, and consuming real-time updates from AWS IoT MQTT.
Features
- AWS Cognito username/password authentication with automatic region discovery.
- Automatic token refresh and header management for all REST calls.
- AWS IoT Device SDK (SigV4 over WebSockets) for MQTT with wildcard subscriptions.
- Zlib-aware payload decoding with header preservation for Hydros messages.
- Helpers for S3 signed URL retrieval and JSON decoding.
- Dedicated exception hierarchy for clearer error reporting.
⚠️ Safety Warning & Disclaimer
pyHydros is provided "as is" and "with all faults", without warranty of any kind, express or implied. The author makes no representations or guarantees regarding safety, suitability, accuracy, reliability, availability, or fitness for any particular purpose.
This software is not designed, tested, or intended for safety-critical, life-supporting, or fail-safe control systems. Do not rely on this integration for life-critical functions (e.g. temperature control, circulation, oxygenation) or for scenarios where equipment failure could result in property damage (e.g. floods, electrical hazards, or fire).
Use of this software is entirely at your own risk. Improper configuration, software defects, network outages, cloud service changes, or unexpected behavior may result in equipment malfunction, property damage, or loss of aquatic life.
Always validate behavior in a controlled or non-critical environment before enabling automations. For critical functions, use Hydros' native controller features, which are specifically designed with local control, redundancy, and safety safeguards.
In no event shall the author be liable for any direct, indirect, incidental, special, exemplary, or consequential damages arising from the use of, or inability to use, this software.
Nothing in this project constitutes professional, electrical, or safety advice.
This project is an independent, community-driven effort and is not affiliated with, authorized, maintained, or endorsed by CoralVue or Hydros. "Hydros" and "CoralVue" are trademarks of their respective owners and are used for identification purposes only.
Installation
pip install -r requirements.txt
The project currently targets Python 3.9+. Required packages include requests, boto3, python-dotenv, awscrt, and awsiot.
Configuration
Create a .env file alongside this repository with your Hydros credentials:
HYDROS_USERNAME=your@email
HYDROS_PASSWORD=your_password
Usage
Authenticate and Inspect Sensors
from pyhydros import HydrosAPI
client = HydrosAPI()
client.authenticate()
profile = client.get_user()
print("User ID:", client.user_id)
print("Things:", [thing.get("thingName") for thing in profile.get("things", [])])
Subscribe to Real-Time Updates
connect_mqtt now discovers the AWS IoT endpoint from the Hydros API responses and handles the Cognito Identity handshake automatically. Provide the Hydros thing id you wish to monitor:
thing_id = profile["things"][0]["thingName"]
mqtt = client.connect_mqtt(thing_id=thing_id)
def handle_update(topic, payload):
print("Topic:", topic)
print("Payload:", payload)
client.subscribe_thing_status(thing_id, handle_update)
The helper publishes the required LISTEN request so that Hydros starts streaming status updates on the /rsp/# topic family. Incoming payloads are automatically decompressed, parsed as JSON, and annotated with _hydros_header when Hydros prepends header metadata.
Change Controller Mode
change_mode sends a mode-change command, waits for the controller acknowledgement, then verifies the mode actually changed by inspecting the status response:
# Switch to "Water Change" mode (blocks until verified)
client.change_mode(thing_id, "Water Change")
# Switch back to "Normal"
client.change_mode(thing_id, "Normal")
The method performs a three-step verified exchange:
- Publishes
PUT/Mode/<mode>and waits for a200receipt acknowledgement. - Requests a status refresh via
LISTEN/statusc. - Parses the status response and confirms the
modefield matches the requested mode.
If the controller does not acknowledge in time, returns a non-200 status, or reports a different mode in the status response, a HydrosMQTTError is raised.
Note: The Hydros controller returns
200for any mode name — even invalid ones. The200only confirms message receipt, not that the mode was applied. The status verification step is what catches invalid or failed mode changes.
REST and S3 Helpers
metadata = client.get_thing(thing_id)
signed_url = client.get_signed_url(thing_id)
config_json = client.download_hydros_data_json(thing_id)
All REST helpers call _ensure_authenticated first, guaranteeing valid tokens.
Exception Model
HydrosAuthError: Authentication and token refresh failures.HydrosAPIError: REST or S3 helper issues (for example, failed decompression).HydrosMQTTError: Problems establishing or using the MQTT connection (missing identity id, missing endpoint, publish/subscribe failures, etc.).
Catch these to provide targeted remediation guidance in your applications.
Testing
Run the unit tests with the virtual environment activated:
python -m unittest -v
The suite covers token expiry logic, Cognito error propagation, MQTT precondition checking, dynamic region inference, and MQTT endpoint discovery edge cases.
Versioning & Changelog
This repository uses Semantic Versioning with a pre-1.0 beta line (starting at 0.1.0) and an automated GitHub changelog/release workflow.
- Version source:
__version__in init.py - Changelog: CHANGELOG.md
- Automation: .github/workflows/release-please.yml
To get clean automated changelogs, use Conventional Commit prefixes in PR titles or commit messages:
feat:for new featuresfix:for bug fixesdocs:,chore:,refactor:,test:for other updates- Add
!(for examplefeat!:) for breaking changes
For beta semantics (version < 1.0.0):
feat:bumps minor (0.x.0)fix:bumps patch (0.x.y)- breaking changes can still trigger major semantics when you decide to move to
1.0.0+
Notes
connect_mqttinfers the AWS IoT endpoint from responses to/userand/thing/{id}. If Hydros introduces new field names, update_infer_iot_endpointaccordingly.subscribe_thing_statusqueues subscriptions until the MQTT connection is ready and automatically issues the LISTEN request.- The example script at the bottom of
pyhydros.pydemonstrates a full interactive workflow.
Infrastructure & Polling Politeness
This library interacts with the CoralVue/Hydros cloud infrastructure. To maintain the stability of these services for the entire community avoid pulling api at unreasonable rate (e.g more than every few minutes).
License
Distributed under the terms of the MIT LICENSE file in this repository.
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyhydros-0.4.1.tar.gz.
File metadata
- Download URL: pyhydros-0.4.1.tar.gz
- Upload date:
- Size: 21.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
372dd40205e2d20af911a17fbd313a596ada96e14051624bdc5410931d540814
|
|
| MD5 |
ac0c3421da788127c6d1a4adb5ae7f66
|
|
| BLAKE2b-256 |
5fdd05ca9ce98cc139ef578155f605c1a56964327dd2e16fe2ae1fe57bf084be
|
Provenance
The following attestation bundles were made for pyhydros-0.4.1.tar.gz:
Publisher:
publish-pypi.yml on Bitf1ip/pyhydros
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyhydros-0.4.1.tar.gz -
Subject digest:
372dd40205e2d20af911a17fbd313a596ada96e14051624bdc5410931d540814 - Sigstore transparency entry: 1250698712
- Sigstore integration time:
-
Permalink:
Bitf1ip/pyhydros@62951e5278cbd4dbc9abd36d4d912d777d22f7ec -
Branch / Tag:
refs/tags/0.4.1 - Owner: https://github.com/Bitf1ip
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@62951e5278cbd4dbc9abd36d4d912d777d22f7ec -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyhydros-0.4.1-py3-none-any.whl.
File metadata
- Download URL: pyhydros-0.4.1-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e0dce3e550f5a253e760a0b74b50a459cbcbf7d86b348d05a249dc5d384dc1d
|
|
| MD5 |
3b6e1798ec12d453a8c5f3c87095d064
|
|
| BLAKE2b-256 |
67eea429a0952623465e104dab1b8b11f4beab45d8be77f473e98324e39aaf83
|
Provenance
The following attestation bundles were made for pyhydros-0.4.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on Bitf1ip/pyhydros
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyhydros-0.4.1-py3-none-any.whl -
Subject digest:
3e0dce3e550f5a253e760a0b74b50a459cbcbf7d86b348d05a249dc5d384dc1d - Sigstore transparency entry: 1250698725
- Sigstore integration time:
-
Permalink:
Bitf1ip/pyhydros@62951e5278cbd4dbc9abd36d4d912d777d22f7ec -
Branch / Tag:
refs/tags/0.4.1 - Owner: https://github.com/Bitf1ip
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@62951e5278cbd4dbc9abd36d4d912d777d22f7ec -
Trigger Event:
release
-
Statement type: