Skip to main content

Python client for Kospel C.MI electric heater HTTP API

Project description

kospel-cmi-lib

Python client for the Kospel C.MI electric heater HTTP API.

Features

  • Async-first: Built on asyncio and aiohttp for non-blocking I/O
  • Type-safe: Strict type hinting throughout
  • Registry-driven: Settings defined declaratively in a central registry; dynamic property access on HeaterController
  • Simulator-capable: Full simulator for offline development and testing (no hardware required)
  • Protocol-based: Decoder/encoder interfaces via Python Protocol types
  • Device discovery: probe_device() and discover_devices() to find Kospel devices on the network (no device_id required)

Installation

# With uv (recommended)
uv add kospel-cmi-lib

# With pip
pip install kospel-cmi-lib

Usage

Create a register backend (HTTP or YAML), load a registry config, and pass both to HeaterController. When using HttpRegisterBackend, call aclose() or use the controller as an async context manager to release the HTTP session when done.

Recommended: async context manager (resources released automatically):

import asyncio
import aiohttp
from kospel_cmi.controller.api import HeaterController
from kospel_cmi.controller.registry import load_registry
from kospel_cmi.kospel.backend import HttpRegisterBackend, YamlRegisterBackend


async def main() -> None:
    api_base_url = "http://192.168.1.1/api/dev/65"  # Replace with your heater URL
    registry = load_registry("kospel_cmi_standard")
    async with aiohttp.ClientSession() as session:
        backend = HttpRegisterBackend(session, api_base_url)
        async with HeaterController(backend=backend, registry=registry) as controller:
            await controller.refresh()
            print(controller.heater_mode)  # Access registry-defined settings
            # controller.heater_mode = "manual"  # Modify (if writable)
            # await controller.save()  # Write pending changes to the device
    # Session and controller resources released here


asyncio.run(main())

Alternative: explicit aclose() (for long-lived integrations):

registry = load_registry("kospel_cmi_standard")
controller = HeaterController(backend=HttpRegisterBackend(session, api_base_url), registry=registry)
try:
    await controller.refresh()
    # ... use controller ...
finally:
    await controller.aclose()

For offline development or tests, use the YAML backend (no HTTP, no close needed):

registry = load_registry("kospel_cmi_standard")
backend = YamlRegisterBackend(state_file="/path/to/state.yaml")
controller = HeaterController(backend=backend, registry=registry)
await controller.refresh()

Device Discovery

CLI — scan network and list devices (no config needed):

kospel-discover                    # Scans common subnets
kospel-discover 192.168.101.0/24  # Scan specific subnet

Python API:

import aiohttp
from kospel_cmi import probe_device, discover_devices

async with aiohttp.ClientSession() as session:
    info = await probe_device(session, "192.168.101.49")
    if info:
        print(f"Found: {info.serial_number}, {info.api_base_url}")

    found = await discover_devices(session, "192.168.101.0/24")
    for device in found:
        print(device.host, device.serial_number, device.api_base_url)

Setting Heater Mode

import asyncio
import aiohttp
from kospel_cmi.controller.api import HeaterController
from kospel_cmi.controller.registry import load_registry
from kospel_cmi.kospel.backend import HttpRegisterBackend
from kospel_cmi.registers.enums import CwuMode, HeaterMode

async def main():
    registry = load_registry("kospel_cmi_standard")
    async with aiohttp.ClientSession() as session:
        backend = HttpRegisterBackend(session, "http://192.168.1.1/api/dev/65")
        async with HeaterController(backend=backend, registry=registry) as controller:
            await controller.refresh()

            # Manual heating: mode + temperature in one call (recommended)
            await controller.set_manual_heating(22.0)

            # Or set properties and save
            controller.heater_mode = HeaterMode.WINTER
            controller.manual_temperature = 22.0  # Used when MANUAL mode
            await controller.save()

            # Water: set mode and temperature separately
            await controller.set_water_mode(CwuMode.COMFORT)
            await controller.set_water_comfort_temperature(38.0)
            await controller.set_water_economy_temperature(35.0)

asyncio.run(main())

Documentation

Module Documentation

Module-specific documentation is co-located with the code (GitHub automatically displays these when browsing directories):

  • kospel/ - HTTP API endpoints and protocol
  • registers/ - Register encoding, decoding, and mappings
  • controller/ - YAML registry config and load_registry
  • tools/ - Register scanner and live scanner for reverse-engineering

Project Documentation

  • Development Guide - Contributing and extending the library
  • Architecture - System design, layers, components, and data flow
  • Technical Specs - Implementation details, data formats, protocols, testing, and coding standards

Roadmap

v1.0.0 Engine & Explorer

  1. Local control - basic device functions can be operated using the library
  2. Robust interface - an interface for 3rd party tools (i.e., Home Assistant integration)
  3. Reverse-engineering toolset - kospel-scan-registers and kospel-scan-live for exploring registers

v2.0.0 Plug & Play for Kospel ecosystem

  1. Support multiple device types
  2. Device discovery
  3. Advanced state management (error and warning flags, fault detection, debug)

References

This library was reverse-engineered from JavaScript code used in the heater's web interface. Key findings:

  • Register encoding uses little-endian byte order
  • Flag bits are used for boolean settings within registers
  • Temperature and pressure values are scaled for precision
  • Read-Modify-Write pattern is required for setting flag bits

License

Apache License 2.0

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

kospel_cmi_lib-0.1.0a10.tar.gz (36.0 kB view details)

Uploaded Source

Built Distribution

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

kospel_cmi_lib-0.1.0a10-py3-none-any.whl (48.8 kB view details)

Uploaded Python 3

File details

Details for the file kospel_cmi_lib-0.1.0a10.tar.gz.

File metadata

  • Download URL: kospel_cmi_lib-0.1.0a10.tar.gz
  • Upload date:
  • Size: 36.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kospel_cmi_lib-0.1.0a10.tar.gz
Algorithm Hash digest
SHA256 db384162611ccafdd61ee987deec87c2c0b3d61f11f4beb025c5a8c181b20784
MD5 39105124fa12672b0ed21be824247aad
BLAKE2b-256 84e469ac83e6b5bfbc5d4f30a596a5ec17eef658a79d2320bc5d15bea6773aba

See more details on using hashes here.

Provenance

The following attestation bundles were made for kospel_cmi_lib-0.1.0a10.tar.gz:

Publisher: release-pypi.yml on JanKrl/kospel-cmi-lib

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

File details

Details for the file kospel_cmi_lib-0.1.0a10-py3-none-any.whl.

File metadata

File hashes

Hashes for kospel_cmi_lib-0.1.0a10-py3-none-any.whl
Algorithm Hash digest
SHA256 716b7a74bae2cbb85acba7a8bd3eab1a2d3cf48b93cca4d43b0b4a6c209d0b12
MD5 eb99c9861f961daff872098459f4293f
BLAKE2b-256 2dc7d49e1d78bdf1b125b631abcb81e7fc2e8649573c942684687d43c059c9d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for kospel_cmi_lib-0.1.0a10-py3-none-any.whl:

Publisher: release-pypi.yml on JanKrl/kospel-cmi-lib

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