Skip to content

Commit

Permalink
Add support for DALI 24-bit event messages
Browse files Browse the repository at this point in the history
IEC 62386 part 103 defines "event" messages, which can be sent by
control devices to indicate various inputs or changes. This commit
introduces support for encoding and decoding these messages, as well as
a handful of new sequences for making it easier to work with them.

Support has been added for IEC 62386 part 301 "push button" devices,
further device types should be simple enough to add in later.
Unsupported types will be safely ignored by the library.
  • Loading branch information
sl-wallace committed Aug 9, 2022
1 parent a2ae2ce commit 0cfddb7
Show file tree
Hide file tree
Showing 17 changed files with 2,328 additions and 284 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
flake8 dali --exclude=driver --count --ignore=E741,F403,F405 --show-source --statistics --max-line-length=127
flake8 dali --exclude=driver --count --ignore=E741,F403,F405,W503 --show-source --statistics --max-line-length=127
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
#flake8 dali --exclude=driver --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
Expand Down
22 changes: 14 additions & 8 deletions dali/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def __str__(self):
return "<broadcast (control gear)>"


# Broadcast alias provided for legacy purposes, new code should avoid ambiguity by using
# either GearBroadcast or DeviceBroadcast
# Broadcast alias provided for legacy purposes, new code should avoid
# ambiguity by using either GearBroadcast or DeviceBroadcast
Broadcast = GearBroadcast


Expand Down Expand Up @@ -153,8 +153,9 @@ def __str__(self):
return "<broadcast unaddressed (control gear)>"


# BroadcastUnaddressed alias provided for legacy purposes, new code should avoid
# ambiguity by using either GearBroadcastUnaddressed or DeviceBroadcastUnaddressed
# BroadcastUnaddressed alias provided for legacy purposes, new code should
# avoid ambiguity by using either GearBroadcastUnaddressed or
# DeviceBroadcastUnaddressed
BroadcastUnaddressed = GearBroadcastUnaddressed


Expand Down Expand Up @@ -213,8 +214,8 @@ def __str__(self):
return f"<group (control gear) {self.group}>"


# Group alias provided for legacy purposes, new code should avoid ambiguity by using
# either GearGroup or DeviceGroup
# Group alias provided for legacy purposes, new code should avoid ambiguity
# by using either GearGroup or DeviceGroup
Group = GearGroup


Expand Down Expand Up @@ -287,8 +288,8 @@ def __str__(self):
return f"<address (control gear) {self.address}>"


# Short alias provided for legacy purposes, new code should avoid ambiguity by using
# either GearShort or DeviceShort
# Short alias provided for legacy purposes, new code should avoid ambiguity
# by using either GearShort or DeviceShort
Short = GearShort


Expand Down Expand Up @@ -343,6 +344,11 @@ class Instance:
def __init__(self):
raise NotImplementedError

@property
def value(self):
if hasattr(self, "_value"):
return self._value

def add_to_frame(self, f):
raise NotImplementedError

Expand Down
6 changes: 4 additions & 2 deletions dali/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def _register_subclass(cls, subclass):
subs.append(subclass)

@classmethod
def from_frame(cls, f, devicetype=0):
def from_frame(cls, f, devicetype=0, dev_inst_map=None):
"""Return a Command instance corresponding to the supplied frame.
If the device type the command is intended for is known
Expand All @@ -230,6 +230,8 @@ def from_frame(cls, f, devicetype=0):
:parameter frame: a forward frame
:parameter devicetype: type of device frame is intended for
:param dev_inst_map: An instance of DeviceInstanceTypeMapper to
assist with DALI events
:returns: Return a Command instance corresponding to the
frame. Returns None if there is no match.
Expand All @@ -241,7 +243,7 @@ def from_frame(cls, f, devicetype=0):
subs = cls._framesizes.get(len(f), [])

for c in subs:
r = c.from_frame(f, devicetype=devicetype)
r = c.from_frame(f, devicetype=devicetype, dev_inst_map=dev_inst_map)
if r:
return r

Expand Down
3 changes: 3 additions & 0 deletions dali/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
part 103 ("General requirements - Control devices") and parts 3xx
(particular requirements for control devices).
"""
import dali.device.general
import dali.device.sequences
import dali.device.pushbutton # noqa: F401
Loading

0 comments on commit 0cfddb7

Please sign in to comment.