# scrapers/plum_serial.py
import re, json, time
PLUM_RE = re.compile(rb"PLUM\|([^|]+)\|RATE=([0-9.]+)\|VTBI=([0-9.]+)")

def parse(raw: bytes):
    m = PLUM_RE.search(raw)
    if not m: return None
    dev, rate, vtbi = m.groups()
    return {
        "event_type":  "infusion_pump",
        "device_id":   dev.decode(),
        "rate_ml_h":   float(rate),
        "vtbi_ml":     float(vtbi),
        "timestamp":   time.time()
    }
