Skip to content

Generalize CT002 inspection mode detection for future firmware variants#310

Merged
tomquist merged 4 commits into
developfrom
claude/add-phase-d-inspection-1UXBr
Apr 6, 2026
Merged

Generalize CT002 inspection mode detection for future firmware variants#310
tomquist merged 4 commits into
developfrom
claude/add-phase-d-inspection-1UXBr

Conversation

@tomquist
Copy link
Copy Markdown
Owner

@tomquist tomquist commented Apr 6, 2026

Summary

Updated the CT002 protocol handler to treat any phase value other than A, B, or C as inspection mode, rather than only recognizing 0 and empty values. This makes the implementation more robust to future firmware variants while maintaining backward compatibility.

Key Changes

  • Inspection mode logic: Changed from explicitly checking for "0" and "" to a more general approach that accepts any phase value outside of A, B, C. This accommodates newer Marstek battery firmwares that use D and future markers.
  • Error handling: Removed the early return on invalid phase values. Inspection mode requests are now processed and responded to (as per protocol spec) rather than being rejected.
  • Logging improvements:
    • Updated debug message to indicate "inspection mode" rather than "invalid phase"
    • Changed phase field formatting from string interpolation to %r for clearer representation of empty/special values
    • Simplified phase display in parsed fields log (now shows actual value instead of conditional "(inspection)" text)
  • Documentation: Updated protocol documentation to clarify that inspection mode is triggered by any phase outside A/B/C, with examples of observed values (0, empty, D)

Implementation Details

The change introduces a more forward-compatible design: instead of maintaining a hardcoded list of inspection mode markers, the code now uses an allowlist approach for valid phases. This means future firmware versions with new inspection markers will automatically be handled correctly without code changes.

https://claude.ai/code/session_018ZXk7b7AaPRfPErEqt3BRt

claude added 4 commits April 6, 2026 22:55
Newer Marstek battery firmwares emit phase 'D' during phase detection.
The validator previously rejected this as an invalid phase, leading to
"CT002 request has invalid phase 'D'" warnings and batteries never
being able to commit to a phase. Accept 'D' alongside '0'/empty as
inspection mode so requests are responded to without aggregating
power into per-phase totals.

Refs #305
Rather than enumerate every observed marker (0, empty, D), accept
anything other than A/B/C as inspection mode. Observed markers are
still documented inline so the rationale is preserved.
@tomquist tomquist marked this pull request as ready for review April 6, 2026 23:00
@tomquist tomquist merged commit af3334a into develop Apr 6, 2026
12 checks passed
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.

2 participants