18 lines
647 B
Python
18 lines
647 B
Python
import logging
|
|
from ports import DeviceRepository, ReadingRepository
|
|
from domain.entities import UplinkEvent
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
class UplinkService:
|
|
def __init__(self, devices: DeviceRepository, readings: ReadingRepository):
|
|
self._devices = devices
|
|
self._readings = readings
|
|
|
|
def handle(self, event: UplinkEvent) -> None:
|
|
device_id = self._devices.get_or_create_device_id(event.dev_eui)
|
|
self._readings.insert_reading(device_id, event.pulse_count)
|
|
log.info(
|
|
"[UP] dev_eui=%s | device_id=%s | pulses=%d",
|
|
event.dev_eui, device_id, event.pulse_count
|
|
)
|