Add generic SAE DTC database (1409 codes) with profile-priority fallback
Compiled by the generic-dtc-db workflow (P0/U0/C0/B0 standard codes, system tags + no-start flags). Lives in profiles/_data/generic-dtcs.json (bundled with profiles/, not listed as a vehicle profile). DtcDatabase.get now falls back: profile code -> generic code -> unknown, so any standard code resolves to a description while vehicle profiles still override (e.g. P0148 keeps the 6.0 text). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016yT89n4zR4qbrySoSiEyZs
This commit is contained in:
+25
-2
@@ -81,12 +81,35 @@ class PidRegistry:
|
|||||||
return list(self.presets.keys())
|
return list(self.presets.keys())
|
||||||
|
|
||||||
|
|
||||||
|
_GENERIC = None
|
||||||
|
|
||||||
|
|
||||||
|
def _generic_dtcs():
|
||||||
|
"""Lazy-load the bundled generic SAE DTC database (code -> Dtc)."""
|
||||||
|
global _GENERIC
|
||||||
|
if _GENERIC is None:
|
||||||
|
_GENERIC = {}
|
||||||
|
try:
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from .profile import profiles_dir
|
||||||
|
path = os.path.join(profiles_dir(), "_data", "generic-dtcs.json")
|
||||||
|
for d in json.load(open(path)).get("dtcs", []):
|
||||||
|
_GENERIC[d["code"]] = Dtc(code=d["code"], desc=d.get("desc", ""),
|
||||||
|
system=d.get("system", "powertrain"),
|
||||||
|
no_start=d.get("no_start", False))
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return _GENERIC
|
||||||
|
|
||||||
|
|
||||||
class DtcDatabase:
|
class DtcDatabase:
|
||||||
def __init__(self, profile):
|
def __init__(self, profile):
|
||||||
self._db = {d.code: d for d in profile.dtcs}
|
self._db = {d.code: d for d in profile.dtcs} # profile codes take priority
|
||||||
|
|
||||||
def get(self, code):
|
def get(self, code):
|
||||||
return self._db.get(code) or Dtc(code, "(unknown - look up this code)")
|
return (self._db.get(code) or _generic_dtcs().get(code)
|
||||||
|
or Dtc(code, "(unknown - look up this code)"))
|
||||||
|
|
||||||
def all(self):
|
def all(self):
|
||||||
return list(self._db.values())
|
return list(self._db.values())
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user