22 lines
855 B
Python
22 lines
855 B
Python
from typing import Dict
|
|
from ..models import TelemetryEvent
|
|
|
|
|
|
def parse_telemetry(payload: Dict) -> TelemetryEvent:
|
|
"""Parse a raw telemetry payload into a TelemetryEvent model.
|
|
|
|
This is a lightweight starter adapter; real deployments would include
|
|
robust validation, TLS mutual authentication, and schema versioning.
|
|
"""
|
|
# Minimal mapping with defaults
|
|
return TelemetryEvent(
|
|
site_id=payload.get("site_id", "unknown_site"),
|
|
asset_id=payload.get("asset_id", "unknown_asset"),
|
|
timestamp=payload.get("timestamp", "1970-01-01T00:00:00Z"),
|
|
v_current=float(payload.get("v_current", 0.0)),
|
|
temp=float(payload.get("temp", 0.0)),
|
|
# Support optional vibration data; default to 0.0 if missing
|
|
vibration=float(payload.get("vibration", 0.0)),
|
|
status=payload.get("status"),
|
|
)
|