Skip to main content

aiodynet

An asyncio client for the Signify Dynalite DyNet lighting control bus, through a DyNet TCP gateway (for example a PDEG).

aiodynet only reads and writes the bus. It has no idea what your site looks like: there are no devices, rooms, names or templates here, only the areas, channels, presets and levels that travel on the wire. That makes it a small, predictable base for higher-level code such as the Home Assistant dynalite integration.

  • Typed, immutable messages that validate themselves, so an out-of-range value fails where you wrote it, not on the bus
  • One connection object with a clear lifecycle: connect, reconnect on its own, close cleanly
  • Writes are paced, because gateways drop packets that arrive too quickly
  • No dependencies outside the standard library. Fully typed (py.typed) and checked with mypy --strict
  • A fake gateway in aiodynet.testing for testing your own code without hardware

Requires Python 3.13 or newer.

Quick start

import asyncio

from aiodynet import DynetClient, Level, PresetSelect, Received, SetChannelLevel


def show(received: Received) -> None:
    print(received.packet.hex(), received.message)


async def main() -> None:
    async with DynetClient("192.0.2.10", 50000) as client:
        client.subscribe(show)

        # Recall preset 1 in area 12 over two seconds
        await client.send(PresetSelect(area=12, preset=1, fade=2))

        # Fade channel 3 of area 12 to 40 %
        await client.send(
            SetChannelLevel(area=12, channel=3, level=Level.from_percent(40), fade=1)
        )

        await asyncio.sleep(60)  # watch the bus for a minute


asyncio.run(main())

Concepts

Packets

A Packet is one 8-byte DyNet 1 frame. You rarely build one by hand, but it is always available: every received message comes with the exact packet, and send accepts packets as well as messages.

from aiodynet import Packet

Packet.from_hex("1c 0c 64 00 00 00 ff")  # checksum added for you
Packet.from_hex("1c0c64000000ff75")  # checksum checked
Packet.from_bytes(raw_8_bytes)  # raises InvalidPacketError if bad

Messages

Each message class maps to exactly one wire form. Fields are keyword-only and checked when the object is built. Channels and presets are numbered from 1, as in the DyNet tools and on keypads.

Message Opcode(s) Meaning
PresetSelect 0x00–0x03, 0x0A–0x0D Select preset 1–2048 in an area, with a fade of up to 1310.7 s
LinearPresetSelect 0x65 Select preset 1–256 using the one-byte form some controllers send
PresetReport 0x62 An area reports its current preset
RequestPreset 0x63 Ask an area for its current preset
SetChannelLevel 0x80–0x83 Fade one channel (1–1024) to a level, with a fade of up to 5.1 s
ChannelLevelReport 0x60 A channel reports its target and actual level
RequestChannelLevel 0x61 Ask a channel for its level
FadeChannelToPreset 0x6B Fade one channel, or every channel, to a preset's level
AreaCommand 0x05, 0x06, 0x08, 0x15, 0x16, 0x66 Area commands with no data: step the area level down or up, program the current preset, disable or enable panels, save the current preset (AreaCommandType)
AreaOff, ResetPreset, Panic, Unpanic 0x04, 0x0F, 0x17, 0x18 Area commands with a preset-style fade
AreaToLevel 0x79 Fade every channel in an area to one level
ChannelOff, ChannelOn 0x74, 0x75 Fade a channel, or every channel, to off or full
StopFade 0x76 Stop a channel, or every channel, mid-fade
FadeChannelToLevel 0x71–0x73 The newer channel-level opcodes; scale names which one
RestoreSavedPreset 0x67 Return to the preset saved with SAVE_CURRENT_PRESET
MotionActivitySync 0x2E A motion sensor sharing its activity timer
SetUserPreference, RequestUserPreference, UserPreferenceReport 0x48–0x4A Device-specific 16-bit preference values
RequestPresetLevel, PresetLevelReport 0x91, 0x92 The level a channel has stored for a preset
ClockTime, ClockDate physical 0x50, 0x53 A device setting or broadcasting the time and date
UnknownMessage anything else Passed through unchanged, packet included

Where an opcode can address one channel or the whole area, channel=None means every channel. Fields whose unit the opcode list doesn't pin down are kept raw and named *_raw (for example fade_raw, time_raw), rather than guessed. Area links (0x20–0x23) are left undecoded because the opcode list doesn't say which bit is which area.

PresetSelect, LinearPresetSelect and PresetReport share the base class AreaPresetMessage, so isinstance(message, AreaPresetMessage) catches "this area is now at preset N" however it was sent.

decode(packet) returns the union type AnyMessage, so a match statement ending in assert_never is checked for exhaustiveness by mypy.

Levels

DyNet levels run backwards on the wire (0x01 is 100 %, 0xFF is off). Level keeps the raw byte, so it always round-trips, and converts for you:

Level.from_percent(40)
Level.from_fraction(0.4)
Level(0x80)  # the raw byte
Level.OFF, Level.FULL
level.percent, level.fraction, level.is_off

Messages accept only Level, never a bare number, so a percentage can't be sent as a raw byte by mistake.

Fades

Fades are seconds as float, rounded to the nearest 20 ms step. A fade that a message can't carry raises ValueError rather than being wrapped or clamped: SetChannelLevel holds up to MAX_CHANNEL_FADE (5.1 s) and preset messages up to MAX_PRESET_FADE (1310.7 s).

The client

client = DynetClient(host, port)
await client.connect()  # raises DynetConnectionError if unreachable
...
await client.close()  # always safe, any number of times

or async with DynetClient(host, port) as client:.

  • Connecting. connect makes one attempt and raises if it fails, which suits "not ready yet, try later" handling. After a successful connect the client reconnects on its own after any drop, waiting 1 s at first and up to 60 s between attempts, until you call close.
  • Receiving. subscribe(callback) calls callback(received) in the event loop for every packet, where received.packet is the raw packet and received.message its decoded meaning. It returns an unsubscribe function. A callback that raises is logged and doesn't affect the others.
  • Connection changes. subscribe_connection(callback) reports drops (False) and reconnects (True). client.connected gives the current state.
  • Sending. await send(message_or_packet) returns once the packet has been written. Packets go out one at a time, 0.2 s apart by default (send_interval). If the client isn't connected, or the connection drops before the packet is written, send raises NotConnectedError. Nothing is kept to send later, so a command can't fire long after it was asked for.
  • Queries. await query(RequestPreset(area=12)) sends the request and returns the matching PresetReport (or ChannelLevelReport for a RequestChannelLevel), or raises TimeoutError.
  • Closing. close cancels everything the client started and closes the socket. No callbacks run after it begins.
  • Dead gateways. TCP keepalive is enabled (30 s idle, then 3 probes 10 s apart where the OS supports it), so a gateway that vanishes on a quiet bus is still noticed.

check_connection(host, port) opens and closes a TCP connection without sending anything. It's meant for validating a host and port in a setup flow.

Testing your code

aiodynet.testing.FakeGateway is a real TCP server on localhost that records what clients send and sends whatever you tell it to:

from aiodynet import DynetClient, PresetReport, RequestPreset
from aiodynet.testing import FakeGateway


def site(packet):
    if packet == RequestPreset(area=1).to_packet():
        return [PresetReport(area=1, preset=4)]
    return []


async def test_area_one_is_off():
    async with FakeGateway(replies=site) as gateway:
        async with DynetClient(gateway.host, gateway.port) as client:
            report = await client.query(RequestPreset(area=1))
    assert report.preset == 4

How well each claim is verified

DyNet documentation is thin, so this is the evidence for each encoding:

Encoding Source
Packet layout, checksum DyNet 1 opcode list; every packet in the test fixtures
PresetSelect (banks, fade in 20 ms steps, low byte then high byte) Opcode list, plus byte-for-byte match with the packets dynalite-devices 0.1.47 sends
SetChannelLevel (bank byte offset by one, fade in 20 ms steps) Byte-for-byte match with dynalite-devices 0.1.47
RequestPreset, RequestChannelLevel Byte-for-byte match with dynalite-devices 0.1.47
PresetReport, LinearPresetSelect, ChannelLevelReport, FadeChannelToPreset Opcode list, plus the meaning dynalite-devices 0.1.47 takes from them. Not yet checked against captured traffic
FadeChannelToPreset fade unit Unknown, so it's kept as a raw byte
MotionActivitySync, UserPreferenceReport, ClockTime, ClockDate Opcode list, plus packets captured on a real site (tests/fixtures/site-capture.jsonl). The clock bytes are BCD, and the date packs the day of the week into the top three bits of the month byte; both inferred from that capture
All other extended messages Byte layout from the opcode list only

The dynalite-devices comparison was made black-box: by driving its public API against a fake gateway and recording the bytes, without reading its source. Those vectors are in tests/test_messages.py.

Porting from dynalite-devices

aiodynet replaces the bus layer of dynalite-devices. The mapping of areas and channels to entities, and naming, stay in the integration. To keep existing installs behaving the same:

  • Brightness. dynalite-devices sends HA brightness b (0–255) as the raw level max(1, 255 - b), and reads it back as 255 - raw. Use Level(max(1, 255 - b)) and 255 - level.raw, not from_fraction, to keep the same bytes.
  • Channel fades longer than 5.1 s were clamped to 5.1 s. aiodynet raises instead, so clamp with min(fade, MAX_CHANNEL_FADE) first.
  • Preset fades longer than 1310.7 s crashed dynalite-devices while it built the packet. aiodynet raises a clear ValueError at the call.
  • Pacing. dynalite-devices spaced writes 0.2 s apart. That's the default here too.
  • Queued writes. dynalite-devices queued writes while disconnected. aiodynet raises NotConnectedError instead. Decide in the integration whether to surface it or retry.

Development

uv sync
uv run pytest --cov      # 100 % branch coverage is enforced
uv run ruff check && uv run ruff format --check
uv run mypy

Licence

MIT. Not affiliated with or endorsed by Signify.

Metadata

Release files for aiodynet 0.1.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 aiodynet 0.1.0
File Size Uploaded Provenance Actions
aiodynet-0.1.0.tar.gz 37.7 kB Without provenance Details for aiodynet-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 65.4 kB

Release files / aiodynet-0.1.0.tar.gz

Download URL aiodynet-0.1.0.tar.gz
Size 37.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4be16d5a20c9a5d0ae4ec8e3d789a6c59d02874c61975884aff89f1a5cecf7fc
BLAKE2b-256 checksum
How to use checksums
5f1572aa401e1b7320220421323274e90ab58449300172159950b1f4c6c6adfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / aiodynet-0.1.0-py3-none-any.whl

Download URL aiodynet-0.1.0-py3-none-any.whl
Size 27.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a87f434dace549ae59e56507a06cc5dd3018801c055e9669abbd491a103db057
BLAKE2b-256 checksum
How to use checksums
f21bc74bb837e2858fec49450bc531a267ba5c7128a2fb32952d7755320a66da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for aiodynet 0.1.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