24 lines
645 B
Python
24 lines
645 B
Python
import serial
|
|
import logging
|
|
# import time as sleep
|
|
|
|
from prometheus_async.aio import time
|
|
|
|
from barcode_server.barcode import BarcodeEvent
|
|
from barcode_server.notifier import BarcodeNotifier
|
|
from barcode_server.stats import SERIAL_NOTIFIER_TIME
|
|
|
|
LOGGER = logging.getLogger(__name__)
|
|
|
|
class SerialNotifier(BarcodeNotifier):
|
|
|
|
def __init__(self, path: str, usb: serial):
|
|
super().__init__()
|
|
self.path = path
|
|
self.usb = usb
|
|
|
|
@time(SERIAL_NOTIFIER_TIME)
|
|
async def _send_event(self, event: BarcodeEvent):
|
|
self.usb.write(event.barcode.encode())
|
|
LOGGER.debug(f"Notified {self.path}: {event.barcode}")
|