A Python client for the HannaCloud API
Project description
HannaCloud Python Client
NOT OFFICIALLY SUPPORTED BY HANNA --
A Python client library for interacting with the HannaCloud API. This client provides methods for authentication and device data retrieval. Developped solely for the HannaCloud HomeAssistant integration. At least for now.
Installation
You can install the package using pip:
pip install hanna-cloud
Usage
Here's a basic example of how to use the client:
from hanna_cloud import HannaCloudClient
# Initialize the client
client = HannaCloudClient()
# Authenticate with your email and password
access_token = client.authenticate(email="your-email", password="your-password")
print(f"Access token: {access_token}")
# Get devices
devices = client.get_devices()
print(f"Devices: {devices}")
# Get user info
user_info = client.get_user()
print(f"User info: {user_info}")
# Get last device reading
last_reading = client.get_last_device_reading(device_id)
print(f"Last device reading: {last_reading}")
# Get device log history (example)
log_history = client.get_device_log_history(device_id=device_id)
print(f"Device log history: {log_history}")
# Disable Cl and pH pumps
client.set_remote_hold(device_id=device_id, setting=True)
# Enable Cl and pH pumps
client.set_remote_hold(device_id=device_id, setting=False)
Error Handling
The client provides comprehensive error handling with specific exception classes:
Exception Classes
HannaCloudError: Base exception for all HannaCloud API errorsAuthenticationError: Raised for authentication failuresDeviceNotFoundError: Raised when a device is not foundAPIError: Raised for general API errors with status code and response dataRemoteHoldError: Raised when remote hold operations failDeviceLogError: Raised when device log operations failValidationError: Raised for input validation errors
Example Error Handling
from hanna_cloud.client import (
HannaCloudClient,
AuthenticationError,
DeviceNotFoundError,
ValidationError
)
client = HannaCloudClient()
try:
# This will raise AuthenticationError if not authenticated
devices = client.get_devices()
except AuthenticationError as e:
print(f"Authentication required: {e}")
# Authenticate first
client.authenticate("your-email", "your-password")
devices = client.get_devices()
try:
# This will raise ValidationError for empty device_id
client.get_last_device_reading("")
except ValidationError as e:
print(f"Validation error: {e}")
try:
# This will raise DeviceNotFoundError if device doesn't exist
readings = client.get_last_device_reading("nonexistent_device")
except DeviceNotFoundError as e:
print(f"Device not found: {e}")
Authentication
The client uses email and password authentication. Use the authenticate method to obtain and set the access token for subsequent requests.
API Methods
authenticate(email: str, password: str, key_base64: str) -> str: Authenticate and return access tokenis_authenticated() -> bool: Check if client is authenticatedget_devices() -> list: Get list of user's devicesget_user() -> dict: Get current user informationget_last_device_reading(device_id: str) -> list: Get last reading for a deviceget_device_log_history(device_id: str, from_dt: datetime, to_dt: datetime) -> list: Get device log historyset_remote_hold(device_id: str, setting: bool) -> dict: Set remote hold setting for a device
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 hanna_cloud-0.0.5.tar.gz.
File metadata
- Download URL: hanna_cloud-0.0.5.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ec18795d023b92827870ac150ae588a474f7ac37d26f73629e228e49fff4fee
|
|
| MD5 |
eac5df4be8c64acd5e71ae918637bec0
|
|
| BLAKE2b-256 |
233864819399577fc6454f35e6064dafa474cad06111d98e914531ca948d775a
|
Provenance
The following attestation bundles were made for hanna_cloud-0.0.5.tar.gz:
Publisher:
pypi.yml on bestycame/hanna_cloud
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hanna_cloud-0.0.5.tar.gz -
Subject digest:
2ec18795d023b92827870ac150ae588a474f7ac37d26f73629e228e49fff4fee - Sigstore transparency entry: 311858486
- Sigstore integration time:
-
Permalink:
bestycame/hanna_cloud@dc293878a8f599824d0934c376860e6bb53b0044 -
Branch / Tag:
refs/tags/0.0.5 - Owner: https://github.com/bestycame
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@dc293878a8f599824d0934c376860e6bb53b0044 -
Trigger Event:
release
-
Statement type:
File details
Details for the file hanna_cloud-0.0.5-py3-none-any.whl.
File metadata
- Download URL: hanna_cloud-0.0.5-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f3674ba41343c4be14779986bbefb00d93107e8181de4e0e52e4eddb8906e5a
|
|
| MD5 |
983d6aac81c64d6ace535f7b9f54383f
|
|
| BLAKE2b-256 |
4790727ce20cce55ef57d1b6c84ed3306669c75de39fe840996cd90d994232cd
|
Provenance
The following attestation bundles were made for hanna_cloud-0.0.5-py3-none-any.whl:
Publisher:
pypi.yml on bestycame/hanna_cloud
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hanna_cloud-0.0.5-py3-none-any.whl -
Subject digest:
8f3674ba41343c4be14779986bbefb00d93107e8181de4e0e52e4eddb8906e5a - Sigstore transparency entry: 311858504
- Sigstore integration time:
-
Permalink:
bestycame/hanna_cloud@dc293878a8f599824d0934c376860e6bb53b0044 -
Branch / Tag:
refs/tags/0.0.5 - Owner: https://github.com/bestycame
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@dc293878a8f599824d0934c376860e6bb53b0044 -
Trigger Event:
release
-
Statement type: