Fix HTTP-polled meter configs truncating large JSON responses#535
Fix HTTP-polled meter configs truncating large JSON responses#535tomquist wants to merge 6 commits into
Conversation
The Fronius Solar API (and other verbose HTTP meters) return a multi-KB JSON document, but the generated config left ESPHome's small default receive buffer in place, so the body was truncated and json::parse_json silently failed. The grid reading stayed stuck and the battery went uncontrolled until users manually enlarged the buffer (discussion #534). Emit buffer_size_rx on http_request and max_response_buffer_size on the per-request action (4 KB) so the config works as generated. Update the Fronius ESPHome doc example and add a changelog entry. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEzZ7zoMfEEZt2cyrdiAV4
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEzZ7zoMfEEZt2cyrdiAV4
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThe ESPHome generator now emits larger HTTP buffers for JSON polling and reuses existing ChangesESPHome HTTP buffer and timeout generation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEzZ7zoMfEEZt2cyrdiAV4
|
🚀 Preview for this PR is deployed at It will be live once the GitHub Pages deployment finishes. |
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEzZ7zoMfEEZt2cyrdiAV4
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEzZ7zoMfEEZt2cyrdiAV4
Steering evaluation (base vs head)Overall: 0 improved, 0 regressed, 15 unchanged across 15 metrics — mean 0% (unchanged). Priority: priority-weighted 0% (unchanged) — ✅ no do-no-harm guardrail regressions. Lower is better for every metric. See Metrics are the per-scenario mean of 5 seeds. Aggregate — mean across 32 scenarios
📊 Interactive grid-power charts (zoom / hover / toggle series) are in the self-contained What do these metrics mean?
Per-scenario tables (32 scenarios)full_battery_low_pace — settle 0.0→0.0s, overshoot 0.0→0.0W, RMS 29.1→29.1W
mixed_cadence/eff — settle 50.8→50.8s, overshoot 164.5→164.5W, RMS 21.9→21.9W
mixed_cadence/fair — settle 47.7→47.7s, overshoot 70.4→70.4W, RMS 12.9→12.9W
mixed_cadence_solar/eff — settle 52.5→52.5s, overshoot 384.7→384.7W, RMS 28.6→28.6W
mixed_cadence_solar/fair — settle 56.0→56.0s, overshoot 75.4→75.4W, RMS 23.7→23.7W
mixed_venus_b2500/eff — settle 81.2→81.2s, overshoot 221.9→221.9W, RMS 18.6→18.6W
mixed_venus_b2500/fair — settle 75.4→75.4s, overshoot 231.1→231.1W, RMS 22.3→22.3W
phase_imbalance — settle 53.4→53.4s, overshoot 145.2→145.2W, RMS 30.3→30.3W
single_venus_d_solar — settle 24.2→24.2s, overshoot 94.4→94.4W, RMS 15.9→15.9W
single_venus_d_steps — settle 26.3→26.3s, overshoot 90.3→90.3W, RMS 15.5→15.5W
single_venus_d_washer — settle 0.0→0.0s, overshoot 0.0→0.0W, RMS 61.0→61.0W
single_venus_drain — settle 0.0→0.0s, overshoot 0.0→0.0W, RMS 907.3→907.3W
single_venus_fill — settle 360.0→360.0s, overshoot 0.0→0.0W, RMS 953.6→953.6W
single_venus_noisy — settle 0.0→0.0s, overshoot 0.0→0.0W, RMS 94.3→94.3W
single_venus_pv — settle 0.0→0.0s, overshoot 0.0→0.0W, RMS 60.8→60.8W
single_venus_solar — settle 26.8→26.8s, overshoot 80.3→80.3W, RMS 17.8→17.8W
single_venus_solar_slow — settle 33.9→33.9s, overshoot 68.3→68.3W, RMS 22.8→22.8W
single_venus_steps — settle 26.0→26.0s, overshoot 88.0→88.0W, RMS 14.7→14.7W
single_venus_steps_slow — settle 40.5→40.5s, overshoot 98.5→98.5W, RMS 14.8→14.8W
single_venus_trace — settle 0.0→0.0s, overshoot 0.0→0.0W, RMS 278.9→278.9W
single_venus_washer — settle 0.0→0.0s, overshoot 0.0→0.0W, RMS 61.0→61.0W
two_venus/eff — settle 18.1→18.1s, overshoot 126.1→126.1W, RMS 14.0→14.0W
two_venus/fair — settle 18.4→18.4s, overshoot 116.7→116.7W, RMS 13.8→13.8W
two_venus_noisy/eff — settle 0.0→0.0s, overshoot 0.0→0.0W, RMS 94.3→94.3W
two_venus_noisy/fair — settle 0.0→0.0s, overshoot 0.0→0.0W, RMS 94.2→94.2W
two_venus_slow/fair — settle 41.8→41.8s, overshoot 174.5→174.5W, RMS 14.0→14.0W
two_venus_solar/eff — settle 26.0→26.0s, overshoot 396.6→396.6W, RMS 20.4→20.4W
two_venus_solar/fair — settle 25.9→25.9s, overshoot 151.4→151.4W, RMS 20.4→20.4W
two_venus_trace/eff — settle 0.0→0.0s, overshoot 0.0→0.0W, RMS 283.1→283.1W
two_venus_trace/fair — settle 0.0→0.0s, overshoot 0.0→0.0W, RMS 282.1→282.1W
venus_d_plus_c/eff — settle 20.1→20.1s, overshoot 128.9→128.9W, RMS 14.7→14.7W
venus_d_plus_c/fair — settle 21.6→21.6s, overshoot 121.0→121.0W, RMS 14.6→14.6W
📊 Open the interactive report — |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/ts/generate.ts`:
- Around line 297-304: The `generateEsphome()` flow is emitting a duplicate
top-level `http_request:` block from the meter polling branch, which can
overwrite the shared HTTP settings. Update the logic around the `RX_BUFFER` push
so it contributes `useragent`, `timeout`, and `buffer_size_rx` to the existing
shared `http_request` config instead of appending a second block; use the
existing `http_request` handling in `generateEsphome()` for
`marstek_registration` and `cloud_reporting` as the single source of truth.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 89993f0f-b88a-4618-a42f-76074121547f
📒 Files selected for processing (5)
AGENTS.mdCHANGELOG.mddocs/esphome-powermeters.mdweb/ts/generate.test.tsweb/ts/generate.ts
ESPHome allows only one top-level http_request:. An HTTP-polled meter emits one (useragent + RX buffer) and marstek_registration/cloud_reporting emit another (20s timeout); with both enabled the generated YAML had two http_request: blocks, so ESPHome would drop either the timeout or the new RX buffer. Merge into the meter's single block, bumping its timeout to 20s when a slow feature also needs it. Add a regression test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEzZ7zoMfEEZt2cyrdiAV4
Summary
ESPHome's default HTTP receive buffer is too small for large JSON responses from meters like the Fronius Solar API, causing the response body to be truncated and
json::parse_jsonto silently fail. This fix enlarges the buffer on both the HTTP client and per-request action so generated configs work without manual editing.Changes
Generator (
web/ts/generate.ts):buffer_size_rx: 4096to thehttp_request:blockmax_response_buffer_size: 4096to the per-requesthttp_request.get:actionDocumentation (
docs/esphome-powermeters.md):Tests (
web/ts/generate.test.ts):Changelog (
CHANGELOG.md):Implementation Details
The fix uses a constant
RX_BUFFER = 4096to ensure both buffer settings use the same value. This size accommodates the multi-KB JSON responses from the Fronius Solar API while remaining reasonable for embedded systems.https://claude.ai/code/session_01FEzZ7zoMfEEZt2cyrdiAV4
Summary by CodeRabbit
http_requestbehavior.