Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ Detailed changes
operate on the underling raw int; the others operate on the scaled
value)

- ``Command.devicetype`` now uses ``None`` rather than ``0`` to mean
"no ``EnableDeviceType`` needed", which frees 0 to name the device
type it is, fluorescent lamp control gear. The ``devicetype``
parameter of ``Command.from_frame()`` follows suit, so a frame that
was not preceded by ``EnableDeviceType`` no longer decodes as one
that was preceded by ``EnableDeviceType(0)``. Code that passes
``devicetype=0`` to say "none" must pass ``None`` instead.

- New module ``dali.gear.fluorescent`` with the commands from IEC
62386-201, fluorescent lamp control gear. Part 201 defines a single
application extended command, ``QueryExtendedVersionNumber``.

.. _dali-drivers: https://github.com/sde1000/dali-drivers

0.16 (2026-10-20)
Expand Down
11 changes: 7 additions & 4 deletions dali/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,11 @@ class Command:
# 16-bit frames may be interpreted differently if they are
# preceded by the EnableDeviceType command. If a command needs
# EnableDeviceType(foo) to be sent first, override devicetype to
# foo. This parameter is ignored for all other frame lengths.
devicetype = 0
# foo; None means the command must not be preceded by one. Device
# type 0 is fluorescent lamp control gear, IEC 62386-201, so zero
# is a device type like any other. This parameter is ignored for
# all other frame lengths.
devicetype: Optional[int] = None

_commands: set[type[Command]] = set()
_supported_devicetypes: set[int] = set()
Expand All @@ -279,7 +282,7 @@ class Command:
def __init_subclass__(cls) -> None:
if cls.__name__[0] != '_':
cls._commands.add(cls)
if cls.devicetype != 0:
if cls.devicetype is not None:
cls._supported_devicetypes.add(cls.devicetype)
subs = cls._framesizes.setdefault(cls._framesize, list())
subs.append(cls)
Expand All @@ -294,7 +297,7 @@ def __init__(self, f: frame.ForwardFrame) -> None:

@classmethod
def from_frame(
cls, f: frame.ForwardFrame, devicetype: int = 0,
cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[DITM] = None
) -> Optional[Command]:
"""Return a Command instance corresponding to the supplied frame.
Expand Down
18 changes: 9 additions & 9 deletions dali/device/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init_subclass__(cls) -> None:
cls._devicecommands.append(cls)

@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None
) -> Optional[_DeviceCommand]:
# In 24-bit frames, bit 16 is 1 for "commands" (as opposed to "events")
Expand Down Expand Up @@ -103,7 +103,7 @@ class UnknownDeviceCommand(_DeviceCommand):
"""An unknown command addressed to a control device.
"""
@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None) -> None:
return None

Expand Down Expand Up @@ -167,7 +167,7 @@ def __init_subclass__(cls) -> None:
cls._opcodes[cls._opcode] = cls

@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None
) -> Optional[_DeviceCommand]:
if f[16:8] != 0x1FE:
Expand Down Expand Up @@ -561,7 +561,7 @@ def __init_subclass__(cls) -> None:
cls._opcodes[cls._opcode] = cls

@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None
) -> Optional[_DeviceCommand]:
# In 24-bit frames, bit 16 is 1 for "commands" (as opposed to "events")
Expand Down Expand Up @@ -803,7 +803,7 @@ def __init__(self) -> None:
)

@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None
) -> Optional[_SpecialDeviceCommand]:
if cls == _SpecialDeviceCommand:
Expand All @@ -827,7 +827,7 @@ def __init__(self, param: int) -> None:
super().__init__()

@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None
) -> Optional[_SpecialDeviceCommandOneParam]:
if cls == _SpecialDeviceCommandOneParam:
Expand Down Expand Up @@ -855,7 +855,7 @@ def __init__(self, a: int, b: int) -> None:
super().__init__()

@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None
) -> Optional[_SpecialDeviceCommandTwoParam]:
if cls == _SpecialDeviceCommandTwoParam:
Expand Down Expand Up @@ -1212,7 +1212,7 @@ class could be the same for multiple data.

@classmethod
def from_frame(
cls, f: frame.ForwardFrame, devicetype: int = 0,
cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None
) -> Optional[_Event]:
# In 24-bit frames, bit 16 is 0 for "events"
Expand Down Expand Up @@ -1346,7 +1346,7 @@ def event_data(self) -> int:
return self._unhandled_data

@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None) -> None:
return

Expand Down
1 change: 1 addition & 0 deletions dali/gear/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
extensions and control gear specific features).
"""
import dali.gear.general
import dali.gear.fluorescent
import dali.gear.emergency
import dali.gear.incandescent
import dali.gear.converter
Expand Down
26 changes: 26 additions & 0 deletions dali/gear/fluorescent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Commands and responses from IEC 62386 part 201."""

from dali.gear.general import _StandardCommand, QueryExtendedVersionNumberMixin


class _FluorescentCommand(_StandardCommand):
devicetype = 0


###############################################################################
# Commands from IEC 62386-201 section 11.3.1
###############################################################################


class QueryExtendedVersionNumber(QueryExtendedVersionNumberMixin,
_FluorescentCommand):
"""Query Extended Version Number

Returns the version number of IEC 62386-201 implemented by the
control gear.

This is the only application extended command defined by part 201:
everything fluorescent lamp control gear can be asked to do is in
part 102. Opcodes 224 to 254 are reserved and shall be ignored.
"""
pass
26 changes: 16 additions & 10 deletions dali/gear/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init_subclass__(cls) -> None:
cls._gearcommands.append(cls)

@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None
) -> Optional[_GearCommand]:
for gc in cls._gearcommands:
Expand Down Expand Up @@ -62,7 +62,7 @@ class UnknownGearCommand(_GearCommand):
"""An unknown command addressed to control gear.
"""
@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None) -> None:
return None

Expand Down Expand Up @@ -125,7 +125,8 @@ def __init__(self, destination: address.GearAddress,
super().__init__(f)

# (devicetype, opcode) -> commandclass
_opcodes: dict[tuple[int, int], type[_StandardCommand]] = {}
_opcodes: dict[tuple[Optional[int], int],
type[_StandardCommand]] = {}

def __init_subclass__(cls) -> None:
super().__init_subclass__()
Expand All @@ -140,7 +141,7 @@ def __init_subclass__(cls) -> None:
cls._opcodes[(cls.devicetype, cls._cmdval)] = cls

@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None
) -> Optional[_GearCommand]:
if not f[8]:
Expand Down Expand Up @@ -212,7 +213,7 @@ def __init__(self, destination: address.GearAddress,
super().__init__(f)

@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None
) -> Optional[_GearCommand]:
if f[8]:
Expand Down Expand Up @@ -1052,7 +1053,11 @@ class QueryExtendedVersionNumber(QueryExtendedVersionNumberMixin,
_StandardCommand):
"""Query Extended Version Number

For device type 0, this command is ignored.
Not preceded by an EnableDeviceType command, so control gear will
ignore it. This exists to decode such a frame when it is seen on
the bus, and to ask about a device type chosen at run time by
sending EnableDeviceType explicitly beforehand; to query a device
type known in advance, use its own implementation instead.
"""
pass

Expand Down Expand Up @@ -1102,7 +1107,7 @@ def __init_subclass__(cls) -> None:
cls._opcodes[cls._cmdval] = cls

@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None
) -> Optional[_GearCommand]:
opcode = f[15:8]
Expand Down Expand Up @@ -1143,7 +1148,7 @@ def __init__(self, address: int | Literal["MASK"]) -> None:
super().__init__((self.address << 1) | 1)

@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None
) -> Optional[_ShortAddrSpecialCommand]:
if cls == _ShortAddrSpecialCommand:
Expand Down Expand Up @@ -1212,7 +1217,7 @@ def __init__(self, broadcast: bool = False,
super().__init__(b)

@classmethod
def from_frame(cls, f: frame.ForwardFrame, devicetype: int = 0,
def from_frame(cls, f: frame.ForwardFrame, devicetype: Optional[int] = None,
dev_inst_map: Optional[command.DITM] = None
) -> Optional[_SpecialCommand]:
if f[15:8] == cls._cmdval:
Expand Down Expand Up @@ -1333,7 +1338,8 @@ class QueryShortAddress(_SpecialCommand):
class EnableDeviceType(_SpecialCommand):
"""This command shall be sent before an application extended command.
This command can be processed without the use of the Initialise()
command. This command shall not be used for device type 0.
command. The valid range of the parameter is 0 to 254; device type
0 is fluorescent lamp control gear, described in IEC 62386-201.
"""
_cmdval = 0xc1
_hasparam = True
Expand Down
29 changes: 15 additions & 14 deletions dali/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,37 @@
from dali.gear import general as generalgear


def _test_pattern() -> Iterable[tuple[int, int | Iterable[int], int]]:
# Control gear, device type zero
def _test_pattern() -> Iterable[
tuple[int, int | Iterable[int], int | None]]:
# Control gear, no preceding EnableDeviceType
for d in range(0, 0x10000):
yield 16, d, 0
# Control gear, device type non-zero, application extended commands only
yield 16, d, None
# Control gear, application extended commands only
for dt in command.Command._supported_devicetypes:
for a in range(1, 0x100, 2):
for b in range(0xe0, 0x100):
yield 16, (a, b), dt
# Control devices, device commands only
for a in range(0, 0x100):
for b in range(0, 0x100):
yield 24, (a, 0xfe, b), 0
yield 24, (a, 0xfe, b), None
# Control devices, instance commands addressed to broadcast device addr
for d in range(0, 0x10000):
yield 24, 0xff0000 | d, 0
yield 24, 0xff0000 | d, None
# Control devices, special commands
for c in range(0, 0x100):
yield 24, (0xc1, c, 0x00), 0
yield 24, (0xc1, c, 0x00), None
for c in (0xc5, 0xc7, 0xc9):
yield 24, (c, 0x00, 0x00), 0
yield 24, (c, 0x00, 0x00), None
# Control devices, event messages for push buttons (part 301)
for e in (0, 1, 2, 5, 9, 11, 12, 14, 15):
yield 24, (0xc2, 0x04, e), 0
yield 24, (0xc2, 0x04, e), None
# Control devices, QueryEventFilter
for o in (0x90, 0x91, 0x92):
yield 24, (0x03, 0x00, o), 0
yield 24, (0x03, 0x00, o), None
# Control devices, events for occupancy sensors (part 303)
for e in range(16):
yield 24, (0x86, 0xFC, e), 0
yield 24, (0x86, 0xFC, e), None


class TrialEnum(enum.IntEnum):
Expand Down Expand Up @@ -398,9 +399,9 @@ def test_response(self) -> None:
def test_queryextendedversionnumber(self) -> None:
"""all gear types implement QueryExtendedVersionNumber"""
# dali.gear.general.QueryExtendedVersionNumber is an oddity:
# it is only used when preceded by EnableDeviceType with
# devicetype != 0. Ensure that there is an implementation of
# this command for all supported device types.
# it is only used when preceded by EnableDeviceType. Ensure
# that there is an implementation of this command for all
# supported device types.
qevn_frame = generalgear.QueryExtendedVersionNumber(
address.Broadcast()).frame
for devicetype in command.Command._supported_devicetypes:
Expand Down