Skip to main content

KNXDclient

A pure Python async client for KNXD's (EIBD's) native Layer 4 KNX protocol.

EIBD is a *NIX daemon for routing EIB/KNX telegrams through various interfaces and programmatically accessing the EIB/KNX bus. It's part of the no-longer maintained BCUSDK. However, there's a fork called KNXD, which is still actively maintained.

This package reimplements small parts of the EIBD client (see BCUSDK documentation, section 7.7) in pure Python 3, based on asynchronous coroutines (asyncio). Currently, it allows to open a Group Socket for sending and receiving KNX telegrams to/for any group address via KNXD. Additionally, this package includes helper methods encode_value() and decode_value() to convert the send/received data from/to native Python types according to a known KNX Datapoint Type (DPT).

Usage example

import asyncio
import knxdclient


def handler(packet: knxdclient.ReceivedGroupAPDU) -> None:
    print("Received group telegram: {}".format(packet))

async def main() -> None:
    # Raises a TimeoutError after 30 seconds of not receiving any traffic. This argument is optional
    connection = knxdclient.KNXDConnection(timeout=30.0) 
    connection.set_group_apdu_handler(handler)
    await connection.connect()
    # Connection was successful. Start receive loop:
    run_task = asyncio.create_task(connection.run())
    # Now that the receive loop is running, we can open the KNXd Group Socket:
    await connection.open_group_socket()

    # Startup completed. Now our `handler()` will receive incoming telegrams and we can send some:
    await connection.group_write(knxdclient.GroupAddress(1,3,2),
                                 knxdclient.KNXDAPDUType.WRITE,
                                 knxdclient.encode_value(True, knxdclient.KNXDPT.BOOLEAN))
    
    await asyncio.sleep(5)
    # Let's stop the connection and wait for graceful termination of the receive loop:
    await connection.stop()
    await run_task


asyncio.run(main())

Alternatively, an async iterator can be used for receiving group telegrams:

import asyncio
import knxdclient

# KNX Datapoint Types of some known group addresses, used for decoding incoming values and encoding group RESPONSE
DPTs = {
    knxdclient.GroupAddress(1, 2, 3): knxdclient.KNXDPT.BOOLEAN,
    knxdclient.GroupAddress(4, 5, 6): knxdclient.KNXDPT.FLOAT16,
}

# Some values for responding to group READ telegrams
CURRENT_VALUE = {
    knxdclient.GroupAddress(1, 2, 3): True
}


async def main() -> None:
    connection = knxdclient.KNXDConnection()
    await connection.connect()
    try:
        # Start run task and open group socket
        run_task = asyncio.create_task(connection.run())
        await connection.open_group_socket()

        # Iterate asynchronously over incoming group telegrams
        packet: knxdclient.ReceivedGroupAPDU
        async for packet in connection.iterate_group_telegrams():
            # Respond to GROUP READ telegrams with known values from CURRENT_VALUE dict
            if packet.payload.type == knxdclient.KNXDAPDUType.READ:
                address = packet.dst
                if address in CURRENT_VALUE:
                    await connection.group_write(address,
                                                 knxdclient.KNXDAPDUType.RESPONSE,
                                                 knxdclient.encode_value(CURRENT_VALUE[address], DPTs[address]))
            # Decode and log incoming group WRITE and RESPONSE telegrams 
            else:
                if packet.dst not in DPTs:
                    # Skip telegrams with unknown datatype
                    continue
                value = knxdclient.decode_value(packet.payload.value, DPTs[packet.dst])
                print(f"Telegram from {packet.src} to GAD {packet.dst}: {value}")

    finally:
        # Let's stop the connection and wait for graceful termination of the receive loop:
        await connection.stop()
        await run_task


asyncio.run(main())

License

This package is published under the terms of the Apache License 2.0.

Metadata

Release files for knxdclient 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for knxdclient 1.2.0
File Size Uploaded Provenance Actions
knxdclient-1.2.0.tar.gz 22.9 kB Without provenance Details for knxdclient-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for knxdclient 1.2.0
File Interpreter ABI Platform Actions
knxdclient-1.2.0-py3-none-any.whl Python 3 none any Details for knxdclient-1.2.0-py3-none-any.whl

Total release size: 43.1 kB

Release files / knxdclient-1.2.0.tar.gz

Download URL knxdclient-1.2.0.tar.gz
Size 22.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7c1478ffbc6bd7b9e99d47f34029ae3e0480240e37803ae923f6013bb8c7dd13
BLAKE2b-256 checksum
How to use checksums
7ed6c2d552615a8746ba37ce6e8b6cab8ddf9b5ffdd3b76b97304f36911f2c5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / knxdclient-1.2.0-py3-none-any.whl

Download URL knxdclient-1.2.0-py3-none-any.whl
Size 20.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90545d80ff9988ee3bb9a22447a26c629672b595674a1d640312513872109e7c
BLAKE2b-256 checksum
How to use checksums
fc36e21f0829c178f4c444e45483d145421ebdb64a7a5d6125071dfcec1da986
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for knxdclient 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page