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-2.0.10.tar.gz (71.0 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-2.0.10-py3-none-any.whl (41.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for habitron_client-2.0.10.tar.gz
Algorithm Hash digest
SHA256 fc8595e47a67894b85caa45c4858ab476529f6a8515dedc26e2ef18c58553da6
MD5 73f4c0804981cbff1c3048e052d03580
BLAKE2b-256 68ee8c67dbc5568e010b3a1c68a9f8dc431f17525be9396f764e05bb9720790b

See more details on using hashes here.

Provenance

The following attestation bundles were made for habitron_client-2.0.10.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-2.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for habitron_client-2.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 69f4eb11316698705286e454d7311543a96e2042dd5bb5dae98348d875c0a0ae
MD5 3318f7b12e460c021cbd6e5d023c6937
BLAKE2b-256 adc2f8da2f6a84fbfe93c6b4b557c73d52e88682396f73ecfa3f8670fd455dca

See more details on using hashes here.

Provenance

The following attestation bundles were made for habitron_client-2.0.10-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