Skip to content

Dt0 device type support typing & firmware transfer - #171

Closed
huetti79 wants to merge 6 commits into
sde1000:masterfrom
tridonic-com:dt0-device-type-support-typing
Closed

huetti79 wants to merge 6 commits into
sde1000:masterfrom
tridonic-com:dt0-device-type-support-typing

Conversation

@huetti79

Copy link
Copy Markdown

PR description — sde1000/python-dali

Branch: tridonic-com/python-dali:dt0-device-type-support-typing → sde1000/python-dali:master
Scope: 5 commits, 18 files, +1715 / −45

Suggested split. The three features below are independent and each commit stands
alone. If you would rather review them separately, the natural cut is
(1) device types + application-extended sequences, (2) EnableDeviceType(0),
(3) firmware transfer — the last one carries a caveat that should not hold up the
first two.


1. Read the device types of gear that does not report them

A DALI gateway that emulates control gear answers 254 to QUERY DEVICE TYPE while
implementing device type 0. QueryDeviceTypes took that as "no device type" and
returned an empty list, so the gear's device type went unseen.

That meaning only arrives with IEC 62386-102:2014. Annex B of the 2009 edition — the
edition this gear reports — reserves 128 to 254 for control devices and gives control
gear no way to say it has no device type at all, so 254 from such gear says nothing
about what it implements.

Measured on the device (Lunatone DALI-2 USB PS, art. 24138246, on a gateway-emulated
control gear at short address 0):

Query Answer
QueryVersionNumber 1 — part 102 edition 1
QueryDeviceType (×3) 254, consistently
QueryNextDeviceType no answer
EnableDeviceType(0) + QueryExtendedVersionNumber 1
EnableDeviceType(1…15) + QueryExtendedVersionNumber no answer
QueryExtendedVersionNumber with no prefix no answer

The last row is the control: the gear does honour EnableDeviceType, so the single
answer at device type 0 is the Annex A.4 signature and not an artefact.

This falls back to the Annex A.4 probe for gear answering 254, and for gear that
answers MASK without implementing QueryNextDeviceType to enumerate with — which
previously raised DALISequenceError for gear working exactly as its edition of the
standard says. Gear that genuinely has no device type answers none of the probes and
is still reported as having none.

Also fixes the ascending-order check on QueryNextDeviceType answers, which compared
each answer against 0 rather than against the previous one, so a first answer of 0
was rejected and the order went unchecked thereafter.

2. Application-extended sequences for DT8, DT6 and DT1

An application extended command is ignored unless EnableDeviceType for its part 2xx
type immediately precedes it, which a caller sending the command on its own does not
get. Adds the sequence wrappers that arrange it:

  • QueryDT8ColourTypeFeatures, QueryDT8ColourStatus — which colour types a gear
    supports and which is active
  • QueryDT6DimmingCurve — tells a linear curve from the standard logarithmic one
  • EmergencyCommand — carries any single DT1 command, the tests, resets and mode
    changes among them

3. Allow commands to ask for EnableDeviceType(0) ⚠️ breaking

Device type 0 is fluorescent lamp control gear, IEC 62386-201, and its application
extended commands must be preceded by EnableDeviceType(0) like any other type's.
Command.devicetype could not express that: 0 was the value meaning "send this
command on its own", so EnableDeviceType was documented as unusable for device
type 0 and part 201 could not be implemented at all.

None now means "no EnableDeviceType needed", which leaves every value the standard
allows for the parameter, 0 to 254, free to mean the device type it names. The
devicetype parameter of from_frame() follows suit, so a frame that was not
preceded by EnableDeviceType no longer decodes as one that was preceded by
EnableDeviceType(0).

Downstream impact: code passing devicetype=0 to mean "none" must pass None.
The companion driver change is a separate PR against dali-drivers; see the note at
the bottom.

Adds dali.gear.fluorescent with the single application extended command part 201
defines, QueryExtendedVersionNumber.

4. Firmware transfer (IEC 62386-105) ⚠️ please read

Firmware transfer uses 32-bit forward frames carrying their destination in the most
significant byte, so the addresses are a family of their own rather than a variant of
GearAddress or DeviceAddress: a transfer is addressed to a bus unit whether that
unit is control gear or a control device.

  • dali.firmware — the commands, plus a FirmwareAddress family in dali.address
  • dali.firmware_sequences — sequences that drive an image onto a unit and that find
    the units supporting transfer at all
  • examples/async-firmware-update.py

Caveat: the order of the commands in these sequences has been inferred from the
command set, not read out of IEC 62386-105, and has not been run against hardware that
accepts a firmware image. The commands and framing are exercised by unit tests only.
Please treat this part as needing a check against the standard before release — it is
why I would be happy to see it split into its own PR.


Testing

  • pytest dali/ — 175 passed
  • mypy --strict dali/ — clean (the branch keeps the typing baseline: master
    before this change is also clean at 46 files, this is clean at 50)
  • flake8 dali — 0
  • Device-type behaviour verified end to end against real hardware (Lunatone DALI-2 USB
    PS + the emulating gateway above): QueryDeviceTypes returns [] before the change
    and [0] after it, and the new tests fail without the change.

CHANGES.rst is updated for each item.

Notes for the reviewer

  • Based on master with upstream/master merged in, so it already carries the typing
    rework and release 1.0a2.
  • dali/firmware.py uses __init_subclass__ rather than the removed
    Command._register_subclass().
  • A companion PR against dali-drivers carries the driver halves of items 3 and 4.
    It must not merge before this one: with a driver checking
    cmd.devicetype is not None against a library where the default is still 0, every
    general command would be prefixed with EnableDeviceType(0).

🤖 Generated with Claude Code

ulrich.huettinger@tridonic.com and others added 6 commits November 23, 2026 18:06
A DALI gateway that emulates control gear answers 254 to
QueryDeviceType, reports part 102 version 1, and implements device
type 0: enabling device type 0 and asking QueryExtendedVersionNumber
gets an answer, and no other device type does.

QueryDeviceTypes took 254 as "no device type" and returned an empty
list, so the gear's device type went unseen. That meaning only arrived
with IEC 62386-102:2014. Annex B of the 2009 edition, the edition this
gear reports, reserves 128 to 254 for control devices and gives
control gear no way to say it has no device type at all, so 254 from
such gear says nothing about what it implements.

Annex A.4 of the 2014 edition covers reading the types in that case:
only the device types the gear implements answer
QueryExtendedVersionNumber, so enabling each in turn and asking
reveals the lot. Use it both for gear answering 254 and for gear that
answers MASK without implementing QueryNextDeviceType to enumerate
with, which previously raised DALISequenceError for gear working
exactly as its edition of the standard says. Gear that really has no
device type answers none of the probes and is still reported as having
none.

The ascending-order check on QueryNextDeviceType answers compared each
against 0 rather than against the previous answer, so a first answer
of 0 was rejected and the order went unchecked after that.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
An application extended command is ignored unless EnableDeviceType for
its part 2xx type immediately precedes it, which a caller sending the
command on its own does not get. Three queries and the DT1 commands
were left without the sequence wrapper that arranges it.

QueryDT8ColourTypeFeatures and QueryDT8ColourStatus report which
colour types a gear supports and which one is active; QueryDT6DimmingCurve
reports the configured curve, so a linear one can be told from the
standard logarithmic one. EmergencyCommand carries any single DT1
command, the tests, resets and mode changes among them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Device type 0 is fluorescent lamp control gear, IEC 62386-201, and its
application extended commands must be preceded by EnableDeviceType(0)
just like those of any other device type. Command.devicetype could not
express that: 0 was the value meaning "send this command on its own",
so EnableDeviceType was documented as unusable for device type 0, and
part 201 could not be implemented at all.

Use None for "no EnableDeviceType needed" instead, which leaves every
value the standard allows for the command parameter, 0 to 254, free to
mean the device type it names. The devicetype parameter of from_frame
follows suit, so a frame that was not preceded by EnableDeviceType no
longer decodes as one that was preceded by EnableDeviceType(0).

Add dali.gear.fluorescent with the one application extended command
part 201 defines, QueryExtendedVersionNumber; opcodes 224 to 254 are
reserved there and control gear shall not react to them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Firmware transfer uses 32-bit forward frames which carry their
destination in the most significant byte, so the addresses are a
family of their own rather than a variant of GearAddress or
DeviceAddress: a transfer is addressed to a bus unit whether that unit
is control gear or a control device.

Add dali.firmware with the commands and dali.firmware_sequences with
the sequences that drive an image onto a unit and that find the units
supporting transfer at all. The order of the commands has been
inferred from the command set, not read out of the standard, so check
it against IEC 62386-105 before running it against hardware.

The drivers that carry 32-bit frames live in dali-drivers; this is the
library half only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The examples moved to importing their drivers from dali-drivers in
5f3cac2 and c6b4126; the firmware update example arrived alongside
that and still imported them from the removed dali.driver.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@sde1000

sde1000 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

This pull request needs splitting into multiple parts.

Commit 0956cbb should be a separate pull request. I need to sanity check it against the standards before accepting it.

Commit 8bb9d68 will be rejected — see pull request #157. You have misunderstood how drivers are supposed to process commands that require EnableDeviceType().

Commit 2a14be1 should be a separate pull request.

Commits 4f013aa and 6714f15 should be a separate pull request. Support for firmware updates over 32-bit frames is a major new feature and needs considering on its own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants