Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sde1000/python-dali
Browse files Browse the repository at this point in the history
  • Loading branch information
rnixx committed Dec 18, 2023
2 parents 87864c6 + 0ebccd7 commit 6ebc3b7
Show file tree
Hide file tree
Showing 14 changed files with 827 additions and 127 deletions.
2 changes: 2 additions & 0 deletions dali/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
import dali.device.general
import dali.device.sequences
import dali.device.pushbutton # noqa: F401
import dali.device.occupancy # noqa: F401
import dali.device.light # noqa: F401
22 changes: 16 additions & 6 deletions dali/driver/hid.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,20 @@ def connect(self):
path = glob.glob(self._path)
else:
path = [self._path]
ex = None
if path:
try:
if self._glob:
self._log.debug("trying concrete path %s", path[0])
self._f = os.open(path[0], os.O_RDWR | os.O_NONBLOCK)
except:
except Exception as e:
self._f = None
ex = e
else:
self._log.debug("path %s not found", self._path)
if not self._f:
# It didn't work. Schedule a reconnection attempt if we can.
self._log.debug("hid failed to open %s - waiting to try again", self._path)
self._log.debug("hid failed to open %s (%s) - waiting to try again", self._path, ex)
self._reconnect_task = asyncio.create_task(self._reconnect())
return False
self._reconnect_count = 0
Expand Down Expand Up @@ -402,6 +404,15 @@ async def _power_supply(self, supply_on):
self.disconnect(reconnect=True)
raise CommunicationError

@staticmethod
def _command_mode(frame):
if len(frame) == 8:
return tridonic._SEND_MODE_DALI8
if len(frame) == 16:
return tridonic._SEND_MODE_DALI16
if len(frame) == 24:
return tridonic._SEND_MODE_DALI24
raise UnsupportedFrameTypeError

async def _send_raw(self, command):
frame = command.frame
Expand All @@ -421,8 +432,7 @@ async def _send_raw(self, command):
data = self._cmd(
self._CMD_SEND, seq,
ctrl=self._SEND_CTRL_SENDTWICE if command.sendtwice else 0,
mode=self._SEND_MODE_DALI16 if len(frame) == 16
else self._SEND_MODE_DALI24,
mode=self._command_mode(frame),
frame=frame.pack_len(4))
try:
os.write(self._f, data)
Expand Down Expand Up @@ -518,7 +528,7 @@ async def _bus_watch(self):
frame = dali.frame.BackwardFrame(raw_frame)
elif rtype == self._RESPONSE_NO_FRAME:
frame = "no"
elif rtype == self._RESPONSE_BUS_STATUS \
elif rtype == self._RESPONSE_INFO \
and message[5] == self._BUS_STATUS_FRAMING_ERROR:
frame = dali.frame.BackwardFrameError(255)
else:
Expand Down Expand Up @@ -547,7 +557,7 @@ async def _bus_watch(self):
current_command = None
continue
else:
self._log.debug("Failed config command (second frame didn't match): %s", current_comment)
self._log.debug("Failed config command (second frame didn't match): %s", current_command)
self.bus_traffic._invoke(current_command, None, True)
current_command = None
# Fall through to continue processing frame
Expand Down
Loading

0 comments on commit 6ebc3b7

Please sign in to comment.