|
| 1 | +# Plan 09 — Power Input Methods: Documentation & Feature Completeness |
| 2 | + |
| 3 | +## Your Role: Network & MQTT Specialist + State Machine Specialist |
| 4 | + |
| 5 | +You are implementing Plan 09: comprehensive documentation for all 5 power input |
| 6 | +methods, plus feature gap fixes (API staleness detection, HomeWizard P1 energy data, |
| 7 | +manual IP fallback, and diagnostic counters). |
| 8 | + |
| 9 | +## Plan File |
| 10 | + |
| 11 | +Read the full plan at: `/Users/basmeerman/Downloads/EVSE-team-planning/plan-09-power-input-methods.md` |
| 12 | + |
| 13 | +## Branch & Workflow |
| 14 | + |
| 15 | +- **Branch:** `work/plan-09` |
| 16 | +- **Remote:** Push to `myfork` (basmeerman/SmartEVSE-3.5), NEVER to `origin` |
| 17 | +- **Workflow:** Specification-first for code changes (SbE → test → implement → verify) |
| 18 | +- **Verify after each code increment:** `cd SmartEVSE-3/test/native && make clean test` |
| 19 | +- **Verify firmware builds:** `pio run -e release -d SmartEVSE-3/` |
| 20 | +- **Commit and push after each increment** — do not batch multiple increments into one commit |
| 21 | + |
| 22 | +## GitHub Issues (in order) |
| 23 | + |
| 24 | +1. **#71** — Power Input Methods Documentation (Increment 1) — START HERE |
| 25 | +2. **#72** — API/MQTT Staleness Detection (Increment 2) |
| 26 | +3. **#73** — HomeWizard P1 Energy Data (Increment 3) |
| 27 | +4. **#74** — HomeWizard P1 Manual IP Fallback (Increment 4) |
| 28 | +5. **#75** — Diagnostic Counters (Increment 5) |
| 29 | + |
| 30 | +## File Ownership — YOU OWN THESE |
| 31 | + |
| 32 | +### New files (create these): |
| 33 | +- `docs/power-input-methods.md` — Comprehensive power input guide (Increment 1) |
| 34 | +- `SmartEVSE-3/test/native/tests/test_metering_diagnostics.c` — Diagnostic counter tests (Increment 5) |
| 35 | + |
| 36 | +### Files you modify (YOUR sections only): |
| 37 | +- `SmartEVSE-3/src/mqtt_parser.c` / `mqtt_parser.h` — Add staleness timeout parsing, |
| 38 | + HomeWizardIP command |
| 39 | +- `SmartEVSE-3/src/evse_ctx.h` — Add `api_mains_last_update_ms`, `api_mains_timeout_ms`, |
| 40 | + diagnostic counter fields |
| 41 | +- `SmartEVSE-3/src/evse_state_machine.c` — Staleness check in tick function (CRITICAL — |
| 42 | + must have tests) |
| 43 | +- `SmartEVSE-3/test/native/Makefile` — Add test_metering_diagnostics build rule |
| 44 | +- `README.md` — Add "Power Input Methods" to documentation table |
| 45 | + |
| 46 | +## SHARED FILES — COORDINATE CAREFULLY |
| 47 | + |
| 48 | +These files are also modified by Plan 06 and/or Plan 07: |
| 49 | + |
| 50 | +- **`network_common.cpp`**: You modify `getMainsFromHomeWizardP1()` to read energy |
| 51 | + fields (Increment 3) and add HomeWizardIP manual fallback in mDNS discovery |
| 52 | + (Increment 4). Keep your changes in clearly marked sections with comments like |
| 53 | + `// BEGIN PLAN-09: HomeWizard energy data` and `// END PLAN-09`. |
| 54 | + |
| 55 | +## Architecture Constraints |
| 56 | + |
| 57 | +1. **CRITICAL: `evse_state_machine.c` changes MUST have tests** — this is safety-critical |
| 58 | +2. Staleness detection must use pure C, testable natively |
| 59 | +3. Use `snprintf` everywhere, never `sprintf` |
| 60 | +4. All test functions MUST have SbE annotations (@feature, @req, @scenario, etc.) |
| 61 | +5. Use `test_framework.h` (NOT unity.h) |
| 62 | +6. New `evse_ctx.h` fields must be documented with comments |
| 63 | +7. Never change existing MQTT topic names — only add new ones |
| 64 | +8. Never change existing `/settings` JSON field names — only add new fields |
| 65 | +9. Requirement prefix: `REQ-MTR-` for metering, `REQ-MQTT-` for MQTT |
| 66 | + |
| 67 | +## Increment 1 Detailed Steps (Start Here — Documentation Only) |
| 68 | + |
| 69 | +1. Read the plan's Section 1 (Power Input Method Analysis) thoroughly |
| 70 | +2. Read existing code to verify the data flow descriptions: |
| 71 | + - `main.cpp`: `ModbusRequestLoop()` for Modbus RTU and Sensorbox |
| 72 | + - `esp32.cpp`: `homewizard_loop()` / `getMainsFromHomeWizardP1()` for HomeWizard |
| 73 | + - `network_common.cpp`: MQTT callback for API/MQTT feed |
| 74 | +3. Create `docs/power-input-methods.md` with: |
| 75 | + - Reliability ranking table (most reliable first) |
| 76 | + - Decision tree flowchart (text-based) |
| 77 | + - Per-method setup guide (5 methods) |
| 78 | + - Comparison table |
| 79 | + - Troubleshooting section |
| 80 | +4. Update `README.md` documentation table with link |
| 81 | +5. Commit and push |
| 82 | + |
| 83 | +## Increment 2 Detailed Steps (API/MQTT Staleness — Most Important Code Change) |
| 84 | + |
| 85 | +1. Write SbE scenarios: |
| 86 | + - Given API metering, when no update for 120s, then fall back to MaxMains |
| 87 | + - Given API metering, when update received, then reset staleness timer |
| 88 | + - Given API metering, when staleness detected, then set diagnostic flag |
| 89 | + - Given non-API metering, then staleness check is skipped |
| 90 | +2. Add fields to `evse_ctx.h`: `api_mains_last_update_ms`, `api_mains_timeout_ms` |
| 91 | +3. Write tests in existing test file or new test file |
| 92 | +4. Implement staleness check in `evse_state_machine.c` |
| 93 | +5. Add MQTT parser for timeout setting |
| 94 | +6. Run `make clean test` |
| 95 | +7. Verify firmware builds |
| 96 | + |
| 97 | +## Key References |
| 98 | + |
| 99 | +- MQTT parser pattern: `src/mqtt_parser.c` (see existing `Set/MainsMeter` handler) |
| 100 | +- HomeWizard code: search for `HomeWizard` in `esp32.cpp` and `network_common.cpp` |
| 101 | +- Modbus metering: `main.cpp` `ModbusRequestLoop()` |
| 102 | +- State machine: `src/evse_state_machine.c` |
| 103 | +- Context struct: `src/evse_ctx.h` |
| 104 | +- Test framework: `test/native/include/test_framework.h` |
| 105 | +- Existing meter tests: `test/native/tests/test_meter_decode.c` |
0 commit comments