Skip to content

Wire Apply button to buem-gateway for a live demo run - #97

Merged
jravani merged 1 commit into
mainfrom
demo/buem-gateway-wiring
Jul 24, 2026
Merged

jravani merged 1 commit into
mainfrom
demo/buem-gateway-wiring

Conversation

@jravani

@jravani jravani commented Jul 24, 2026

Copy link
Copy Markdown
Member

Summary

  • Clicking Apply now runs a real BuEM simulation via buem-gateway's POST /buem/building endpoint and feeds the result (load profile + thermal summary) into the existing chart/totals UI, replacing the static placeholder numbers.
  • Adds src/app/lib/buemApi.ts, following the same pattern as the existing ignisApi.ts.
  • Fixes ignisApi.ts calls to send the X-Api-Key header — needed now that ignis sits behind Caddy with API-key auth in the demo stack.

This is demo-only wiring, not the target architecture. In the real system, Building Configurator only collects data; it flows through the EnerPlanET backend and an orchestration layer that dispatches to BuEM. This direct frontend→buem-gateway call exists solely to showcase Building Configurator + ignis + BuEM + Docker working together ahead of that orchestration layer existing.

Depends on enerplanet/buem-gateway#21 (a CORS bug found while testing this — without it, every request from a browser failed with TypeError: Failed to fetch even though buem-gateway responded 200).

Test plan

  • npm run build passes
  • Verified live in a real browser against the local Docker stacks (ignis + buem-gateway):
    • Configuring a wall's U-value live-updates thermal efficiency (ignis path, pre-existing, still works)
    • Apply triggers a real ~8760-point hourly BuEM run (confirmed via network capture, not placeholder data)
    • Monthly load profile chart renders the real values (~7,500–8,500 kWh/month heating)
    • "Download load profile" (Expert mode) produces a correct CSV with the real monthly aggregates

Clicking Apply now builds a BUEM GeoJSON feature from the current
building state and POSTs it to buem-gateway's single-building endpoint
(POST /buem/building), then feeds the real load profile and thermal
summary back into the load profile chart and energy totals — replacing
the static placeholder numbers with a real BuEM physics run.

Also adds the X-Api-Key header ignisApi.ts's calls were missing, needed
now that ignis sits behind Caddy with API-key auth for this demo stack.

This is demo-only wiring, not the target architecture: in the real
system Building Configurator only collects data, which flows through
the EnerPlanET backend and an orchestration layer that dispatches to
BuEM — not a direct frontend-to-service call like this one. Kept here
to showcase Building Configurator + ignis + BuEM + Docker working
together ahead of that layer existing (see buem-gateway's decision
note on this).

Verified live in-browser: Apply triggers a real ~8760-point hourly
BuEM run, the monthly chart and CSV download reflect the real values,
and ignis's live thermal-efficiency recalculation on parameter change
still works.
Copilot AI review requested due to automatic review settings July 24, 2026 06:59
@jravani
jravani merged commit 4b2295f into main Jul 24, 2026
3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Wires the Building Configurator “Apply” flow to run a live BuEM simulation via buem-gateway and display the returned load profile + thermal summary in the existing UI, while also updating ignis API calls to include API-key auth headers for the demo stack.

Changes:

  • Add a new buemApi.ts client that calls POST /buem/building and adapts the response into the app’s LoadDataPoint + thermal summary shapes.
  • Update BuildingConfigurator.tsx so Apply triggers the live simulation, updates chart/totals state, and disables the button while running.
  • Add X-Api-Key header wiring to ignisApi.ts requests (including POST) when configured via env.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/app/lib/ignisApi.ts Adds optional API-key auth headers to ignis fetch calls.
src/app/lib/buemApi.ts Introduces a buem-gateway API client to run building simulations and adapt results for the UI.
src/app/components/BuildingConfigurator/BuildingConfigurator.tsx Hooks “Apply” to the live BuEM run, prioritizes the live timeseries, and adds a running/disabled state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/app/lib/buemApi.ts
Comment on lines +133 to +142
? ts.timestamps.map((timestamp, i) => ({
timestamp,
heating: ts.heating[i] ?? 0,
electricity: ts.electricity[i] ?? 0,
// LoadDataPoint has no cooling field. Reusing "hotwater" for BuEM's
// cooling output matches the existing thermalSummary-based fallback
// in BuildingConfigurator.tsx's computeEnergyTotals — not a
// physically accurate label, but the established convention.
hotwater: ts.cooling?.[i] ?? 0,
}))
Comment on lines +319 to 324
// Hourly timeseries from the most recent live buem-gateway run this session — takes
// priority over whatever timeseries the buildingData prop originally carried.
const [modelTimeseries, setModelTimeseries] = useState<LoadDataPoint[] | null>(null);
const [isRunningSimulation, setIsRunningSimulation] = useState(false);

const fileInputRef = useRef<HTMLInputElement>(null);
@jravani
jravani deleted the demo/buem-gateway-wiring branch August 1, 2026 21:07
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