Skip to main content

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:

  1. Publishes PUT/Mode/<mode> and waits for a 200 receipt acknowledgement.
  2. Requests a status refresh via LISTEN/statusc.
  3. Parses the status response and confirms the mode field 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 200 for any mode name — even invalid ones. The 200 only 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.

To get clean automated changelogs, use Conventional Commit prefixes in PR titles or commit messages:

  • feat: for new features
  • fix: for bug fixes
  • docs:, chore:, refactor:, test: for other updates
  • Add ! (for example feat!:) 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_mqtt infers the AWS IoT endpoint from responses to /user and /thing/{id}. If Hydros introduces new field names, update _infer_iot_endpoint accordingly.
  • subscribe_thing_status queues subscriptions until the MQTT connection is ready and automatically issues the LISTEN request.
  • The example script at the bottom of pyhydros.py demonstrates 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

pyhydros-0.4.1.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhydros-0.4.1-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

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

Hashes for pyhydros-0.4.1.tar.gz
Algorithm Hash digest
SHA256 372dd40205e2d20af911a17fbd313a596ada96e14051624bdc5410931d540814
MD5 ac0c3421da788127c6d1a4adb5ae7f66
BLAKE2b-256 5fdd05ca9ce98cc139ef578155f605c1a56964327dd2e16fe2ae1fe57bf084be

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhydros-0.4.1.tar.gz:

Publisher: publish-pypi.yml on Bitf1ip/pyhydros

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pyhydros-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e0dce3e550f5a253e760a0b74b50a459cbcbf7d86b348d05a249dc5d384dc1d
MD5 3b6e1798ec12d453a8c5f3c87095d064
BLAKE2b-256 67eea429a0952623465e104dab1b8b11f4beab45d8be77f473e98324e39aaf83

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhydros-0.4.1-py3-none-any.whl:

Publisher: publish-pypi.yml on Bitf1ip/pyhydros

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page