Skip to content

feat: /api/v1/snapshot endpoint + wire TUI to real panel data#30

Merged
tim-ireland merged 2 commits into
mainfrom
feat/tui-snapshot-api
Apr 23, 2026
Merged

feat: /api/v1/snapshot endpoint + wire TUI to real panel data#30
tim-ireland merged 2 commits into
mainfrom
feat/tui-snapshot-api

Conversation

@tim-ireland

Copy link
Copy Markdown
Owner

Summary

  • Adds GET /api/v1/snapshot JSON endpoint (unauthenticated, on dashboard routes) that aggregates solar, HVAC, vehicle, energy, weather, and efficiency score in one round-trip
  • Wires flux-tui to this endpoint, fixing three long-standing data gaps:
    • HVAC mode was hardcoded "HEAT" — now shows real operating mode, COP, zone temp → setpoint, and power draw
    • solar_today_kwh was always 0 — now the actual daily yield from the metric cache
    • Vehicle SoC / charge_kw were always 0/None — now real values from the EV connector
  • TUI header gains outdoor temperature and efficiency score when data is available
  • apply_connectors() is now a fallback only used when snapshot is unavailable

Changes

File Change
crates/flux-api/src/routes/panels.rs SnapshotResponse struct + get_snapshot handler
crates/flux-api/src/server.rs Register /snapshot on dashboard routes
bins/flux-tui/src/client.rs HvacUnitData, VehicleData, SnapshotData types + fetch_snapshot()
bins/flux-tui/src/app.rs Extend HvacUnit/Vehicle structs, add apply_snapshot()
bins/flux-tui/src/main.rs Call fetch_snapshot + apply_snapshot in fetch loop
bins/flux-tui/src/ui.rs HVAC table shows 6 columns; header shows weather + score

Test plan

  • All 230+ existing tests pass (just test)
  • just lint clean
  • New unit tests: apply_snapshot_sets_scalar_kw_values, apply_snapshot_populates_hvac_units, apply_snapshot_populates_vehicles, apply_connectors_skips_when_snapshot_data_present, snapshot_data_deserializes_full_payload, snapshot_data_deserializes_with_null_optionals
  • Runtime: TUI HVAC panel shows real operating mode (HEAT/COOL/IDLE), COP, room temp → setpoint, and power draw
  • Runtime: solar panel shows real today's kWh
  • Runtime: vehicle gauge shows real SoC percentage

🤖 Generated with Claude Code

tim-ireland and others added 2 commits April 22, 2026 18:56
The original rule warned when delta < 2°F, labelling it a flow
restriction. This is backwards: Q = flow_gpm × 500 × ΔT, so a
*large* delta at a given load means low flow (pump not moving enough
water). A small delta is normal — low compressor load or high flow.

Changed threshold to > 10°F (normal range is 5–10°F). Added two unit
tests — one for the real 7-series case that triggered the false
positive (1.9°F, now silent) and one for the alert case (11°F).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fixes three data gaps in the TUI:
- HVAC mode was hardcoded to "HEAT" (now real operating mode from metric cache)
- solar_today_kwh was always 0 (now computed from cache via snapshot)
- Vehicle SoC and charge_kw were always 0/None (now real values)

API change:
- New GET /api/v1/snapshot on dashboard_routes (unauthenticated) returns
  SnapshotResponse with solar, HVAC, vehicle, energy, weather, and
  efficiency_score in a single JSON payload

TUI changes:
- FluxClient.fetch_snapshot() calls /api/v1/snapshot
- AppState.apply_snapshot() overwrites all scalar values from snapshot;
  apply_connectors() is now a fallback used only when snapshot data is absent
- HvacUnit gains zone_temp_f, setpoint_f, total_power_w fields
- Vehicle gains range_miles field
- HVAC panel now shows: NAME | MODE | ROOM→SET | COP | POWER | STATUS
- Header now shows outdoor temp and efficiency score when available

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tim-ireland tim-ireland merged commit 18cdf9e into main Apr 23, 2026
1 check passed
@codecov

codecov Bot commented Apr 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 31.57895% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.85%. Comparing base (e78dadf) to head (f3e22eb).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
crates/flux-api/src/routes/panels.rs 0.00% 23 Missing ⚠️
crates/flux-api/src/routes/intel.rs 85.71% 2 Missing ⚠️
crates/flux-api/src/server.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #30      +/-   ##
==========================================
- Coverage   48.95%   48.85%   -0.10%     
==========================================
  Files          69       69              
  Lines        5619     5655      +36     
==========================================
+ Hits         2751     2763      +12     
- Misses       2868     2892      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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