Skip to content

Commit

Permalink
Drop the codes() function
Browse files Browse the repository at this point in the history
  • Loading branch information
lukipuki committed Dec 5, 2023
1 parent 7929527 commit 80ac406
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions python/yaroc/utils/si.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import serial
from pyudev import Device
from serial_asyncio import open_serial_connection
from typing import Iterator

from yaroc.rs import SiPunch

Expand All @@ -35,13 +34,9 @@ async def process_punch(self, punch: SiPunch, queue: Queue):
self._codes.add(punch.code)

def __str__(self):
codes = list(self.codes())
codes_str = ",".join(map(str, codes)) if len(codes) >= 1 else "0"
codes_str = ",".join(map(str, self._codes)) if len(self._codes) >= 1 else "0"
return f"{codes_str}-{self.name}"

def codes(self) -> Iterator[int]:
return self._codes


class SerialSiWorker(SiWorker):
"""Serial port worker"""
Expand All @@ -50,6 +45,7 @@ def __init__(self, port: str):
super().__init__()
self.port = port
self._finished = Event()
self.name = "srr"

async def loop(self, queue: Queue[SiPunch]):
try:
Expand Down Expand Up @@ -119,7 +115,6 @@ async def loop(self, queue: Queue):

class UdevSiFactory(SiWorker):
def __init__(self):
self.name = "srr"
self._udev_workers: Dict[str, tuple[SerialSiWorker, Future]] = {}
self._device_queue: Queue[tuple[str, Device]] = Queue()

Expand Down Expand Up @@ -186,16 +181,13 @@ def stop(self):
def _handle_udev_event(self, action, device: Device):
if not self._is_sl(device) and not self._is_sandberg(device):
return
asyncio.run_coroutine_threadsafe(
self._device_queue.put((action, device)), self._loop
)
asyncio.run_coroutine_threadsafe(self._device_queue.put((action, device)), self._loop)

def codes(self):
union = set()
def __str__(self):
res = []
for worker, _ in self._udev_workers.values():
for c in worker.codes():
union.add(c)
return union
res.append(str(worker))
return ",".join(res)


class FakeSiWorker(SiWorker):
Expand Down

0 comments on commit 80ac406

Please sign in to comment.