Skip to main content

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 errors
  • AuthenticationError: Raised for authentication failures
  • DeviceNotFoundError: Raised when a device is not found
  • APIError: Raised for general API errors with status code and response data
  • RemoteHoldError: Raised when remote hold operations fail
  • DeviceLogError: Raised when device log operations fail
  • ValidationError: 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 token
  • is_authenticated() -> bool: Check if client is authenticated
  • get_devices() -> list: Get list of user's devices
  • get_user() -> dict: Get current user information
  • get_last_device_reading(device_id: str) -> list: Get last reading for a device
  • get_device_log_history(device_id: str, from_dt: datetime, to_dt: datetime) -> list: Get device log history
  • set_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

hanna_cloud-0.0.4.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

hanna_cloud-0.0.4-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file hanna_cloud-0.0.4.tar.gz.

File metadata

  • Download URL: hanna_cloud-0.0.4.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

Hashes for hanna_cloud-0.0.4.tar.gz
Algorithm Hash digest
SHA256 4544a69f477cc8a494a4805e6d335949efbc01cb2a673f5e046b8037c5463b7a
MD5 5a4256492b2491ccbd012553faa2c13d
BLAKE2b-256 bc00e93d68ef5b8193179544701c23ae6054aef62a81652020bbccf3116531d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for hanna_cloud-0.0.4.tar.gz:

Publisher: pypi.yml on bestycame/hanna_cloud

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

File details

Details for the file hanna_cloud-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: hanna_cloud-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for hanna_cloud-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 14ea51a1fdf282b834ec0167f1a3d335719f80bdc425d5c23e74c31a661e66c7
MD5 28a011d2929fa0ebf98cbbc34c3b4c3b
BLAKE2b-256 f3aa86641cb8107e1a49ee709e8afbcc2bd7534ea7d1121dc2e15fc7c58504a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for hanna_cloud-0.0.4-py3-none-any.whl:

Publisher: pypi.yml on bestycame/hanna_cloud

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