Fix: Finanzen-Tab bleibt bei 'Lade...' hängen (v1.8.21)

fEur/fKwh waren lokale Funktionen in renderEnergy() — loadFinance()
konnte sie nicht aufrufen (ReferenceError außerhalb des Scopes).
Beide Funktionen in den globalen Scope verschoben, lokale Kopien entfernt.
loadFinance() Rendering-Block in try/catch gewrappt.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
retr0
2026-05-06 08:18:17 +02:00
parent 7904d498b5
commit cb5f23d486
3 changed files with 14 additions and 10 deletions
+11 -9
View File
@@ -713,6 +713,15 @@ function renderSpotChart(spotData) {
</div>`;
}
function fEur(v) {
if (v == null) return null;
return v >= 100 ? v.toFixed(0) + ' €' : v.toFixed(2) + ' €';
}
function fKwh(v) {
if (v == null) return null;
return (v >= 100 ? v.toFixed(0) : v.toFixed(1)) + ' kWh';
}
function renderEnergy(inverters, aggregates, period, spotData) {
const el = document.getElementById("energy-content");
if (!aggregates || !Object.keys(aggregates).length) {
@@ -848,15 +857,6 @@ function renderEnergy(inverters, aggregates, period, spotData) {
const pi = period.price_import || 0.30;
const pe = period.price_export || 0.08;
function fEur(v) {
if (v == null) return null;
return v >= 100 ? v.toFixed(0) + ' €' : v.toFixed(2) + ' €';
}
function fKwh(v) {
if (v == null) return null;
return (v >= 100 ? v.toFixed(0) : v.toFixed(1)) + ' kWh';
}
function periodCard(label, kwh, cost, col, sub) {
if (kwh == null) return '';
return `<div class="kwh-card" style="border-top:3px solid ${col}">
@@ -937,6 +937,7 @@ async function loadFinance() {
try { data = await fetchJSON(api("api/finance")); }
catch(e) { el.innerHTML = '<div class="no-data">Fehler beim Laden</div>'; return; }
try {
const { days, fixed_total_eur, spot_total_eur, savings_eur, period_start, spot_days, total_days } = data;
if (!days || days.length === 0) {
@@ -1033,6 +1034,7 @@ async function loadFinance() {
</div>`;
el.innerHTML = empfehlung + cards + chart;
} catch(e) { el.innerHTML = '<div class="no-data">Fehler beim Laden</div>'; console.error('loadFinance:', e); }
}
// ── Live Data ─────────────────────────────────────────────────