Skip to main content

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 asyncio StreamReader/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 validated TypedDict models.
  • Async UDP discovery of SmartHubs on the local network.
  • Typed exception hierarchy and a py.typed marker (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


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.3.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

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

habitron_client-1.0.3-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file habitron_client-1.0.3.tar.gz.

File metadata

  • Download URL: habitron_client-1.0.3.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for habitron_client-1.0.3.tar.gz
Algorithm Hash digest
SHA256 76e1b68d4933ade10d3ac93f96e0d3e724ee73ea5ec4009f2f596bd1afb6892d
MD5 3a9296f4c7342784a341617d70268d50
BLAKE2b-256 26063b51733e907264efd84fec631a3396968cdd87a1f33bd03346f83197b282

See more details on using hashes here.

Provenance

The following attestation bundles were made for habitron_client-1.0.3.tar.gz:

Publisher: release.yml on dneprojects/habitron-client

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

File details

Details for the file habitron_client-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: habitron_client-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for habitron_client-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 15a83a2a1482d14d19f5d84847b9772cffbfbeaac5749bc1ad2b13085cf8eb4c
MD5 d4af320055580aa080a6a1469d0c27ea
BLAKE2b-256 97ba0e44f3bba808e5a6d3a8d0af9a38052edf3a920d6038a480aaf93709e4aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for habitron_client-1.0.3-py3-none-any.whl:

Publisher: release.yml on dneprojects/habitron-client

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