Asynchronous, typed API client for the Habitron SmartHub
Project description
Habitron Client
An asynchronous, fully typed API client for the Habitron SmartHub, designed for integration with Home Assistant.
Features
- Non-blocking TCP communication via
asyncioStreamReader/StreamWriter. - Persistent, lock-serialised connection with automatic reconnect on errors.
- Automatic CRC16 calculation and command wrapping.
- High-level coroutines for outputs, dimmers, RGB, shutters, climate and more.
- Safe YAML parsing (
yaml.safe_load) into validatedTypedDictmodels. - Async UDP discovery of SmartHubs on the local network.
- Typed exception hierarchy and a
py.typedmarker (PEP 561 compliant).
Requirements
- Python 3.11+
Installation
pip install habitron-client
Usage
The client is async-only and is used as an async context manager:
import asyncio
from habitron_client import HabitronClient, HabitronError
async def main() -> None:
async with HabitronClient("192.0.2.10") as client:
info = await client.get_smhub_info()
print(info["software"]["version"])
await client.set_output(mod_addr=1, nmbr=2, val=True)
asyncio.run(main())
Error handling
All failures raise a typed exception:
HabitronError (root)
├── HabitronConnectionError (refused / EOF / socket lost)
├── HabitronTimeoutError (no response within the deadline)
└── HabitronProtocolError
├── HabitronChecksumError (CRC mismatch)
└── HabitronBusError (SmartHub reported an error)
Discovery
from habitron_client import discover_smarthubs
hubs = await discover_smarthubs()
Development
pip install -e ".[dev]"
ruff check .
ruff format --check .
mypy --strict src/habitron_client
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
habitron_client-1.0.0.tar.gz
(23.8 kB
view details)
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 habitron_client-1.0.0.tar.gz.
File metadata
- Download URL: habitron_client-1.0.0.tar.gz
- Upload date:
- Size: 23.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
822236a03fb0ccb82013cbffe76d612076311792c189c829e6e13b21fb4f5f0f
|
|
| MD5 |
f605058aefea2319ad2e0cc51f63330b
|
|
| BLAKE2b-256 |
3019c3f9c303b48f7ba67ec12a26bed28a31090552ac85fee31766412339cb0c
|
File details
Details for the file habitron_client-1.0.0-py3-none-any.whl.
File metadata
- Download URL: habitron_client-1.0.0-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ad34d5cbc603b288324562b0e244367b67e8b32197884201e5da5719c08cce7
|
|
| MD5 |
d0c739d23792e665174af60a684104ce
|
|
| BLAKE2b-256 |
cc6636dec7b1af1f2e2e6d9834d3f2a8cf2d2d523b015e514440dbec433cbf0e
|