fix(phase26): persist DTC/MIL state + server speed_source (BUG-03, BUG-05)

BUG-03: DTC/MIL codes were never persisted; lost on OBD disconnect or reboot.
- Add new dtc table schema (code, description, MIL, first/last seen, IS_SET)
  and a migration that rebuilds the original unused NAME/STATUS/DTC_ID table.
- Persist MIL + codes to SQLite on each successful OBD poll (_persist_dtc_state).
- /api/dtc falls back to the last-persisted snapshot when OBD is offline/stale.
- Fix get_overview_stats to count the real dtc table (was querying non-existent
  dtc_codes table).
- Add cleared/since tracking via IS_SET + FIRST_SEEN_AT/LAST_SEEN_AT.

BUG-05: server trip replay hardcoded speed_source:'gps'; mirror Pi's
'obd if speed>0 else gps' logic in server get_trip_route.

Adds tests/test_dtc_persistence.py (7 tests).
This commit is contained in:
Mathieu Moran
2026-08-11 00:38:05 -04:00
parent cd0583ac84
commit e2f2314318
5 changed files with 251 additions and 15 deletions
+3 -1
View File
@@ -443,7 +443,9 @@ def get_trip_route(device_id, trip_id):
"latitude": p[1],
"longitude": p[2],
"speed": p[3] or 0,
"speed_source": "gps",
# Mirror the Pi's route_points: OBD speed when we have it,
# otherwise the point is sourced from GPS.
"speed_source": "obd" if (p[3] or 0) > 0 else "gps",
}
for p in points
],