Skip to content

feat(obd_ai): add normalized JSON serializers - #11

Open
virtuscyber wants to merge 1 commit into
feature/1-obd-ai-foundationfrom
feature/2-obd-ai-json-serializers
Open

virtuscyber wants to merge 1 commit into
feature/1-obd-ai-foundationfrom
feature/2-obd-ai-json-serializers

Conversation

@virtuscyber

Copy link
Copy Markdown
Owner

Refs #2

Stacked on top of #1.

Includes:

  • normalized serializers for OBD responses and diagnostic primitives
  • stable JSON output contract for tool callers
  • coverage for serialization edge cases

@augmentcode

augmentcode Bot commented Apr 11, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR introduces JSON-safe, normalized serializers for python-OBD responses and related diagnostic primitives, and exposes them through the package API.

Changes:

  • Added obd_ai.serializers to serialize OBDResponse, OBDCommand, scalar values, quantities, status/test results, and DTC lists
  • Implemented approved-command descriptor and catalog serialization (optionally including support information)
  • Added connection metadata serialization for transport-level state reporting
  • Extended OBDAISession with serialized query and metadata/descriptor helpers
  • Re-exported serializer helpers from obd_ai.__init__ for a stable public API surface
  • Added tests covering key serialization paths and session helper behavior

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread obd_ai/serializers.py
return raw.decode("ascii")
except UnicodeDecodeError:
return raw.hex()
return str(raw)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_serialize_command_bytes() falls back to str(raw), which will turn None into the string "None" (e.g., if command.header is unset) instead of JSON null, breaking the JSON-safe contract. Consider ensuring None remains None at this boundary.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment thread obd_ai/serializers.py
return {
"type": "connection_metadata",
"status": status,
"is_connected": is_connected,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serialize_connection_metadata() returns status as-is; if callers pass an OBDStatus enum/object, this may not be JSON-serializable and may violate the documented status: str contract. Consider normalizing status to a plain string at the serializer boundary.

Severity: medium

Other Locations
  • obd_ai/session.py:70

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment thread obd_ai/serializers.py
code, description = value
return {
"type": "dtc",
"code": code,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_is_dtc_entry() matches codes case-insensitively via code.upper(), but _serialize_dtc_entry() emits the original code, so inputs like p0101 would produce non-normalized output. If the goal is a normalized JSON contract, consider emitting the uppercased code.

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant