diff --git a/Energy_Pie/module.html b/Energy_Pie/module.html index bbb6623..df59817 100644 --- a/Energy_Pie/module.html +++ b/Energy_Pie/module.html @@ -1,5 +1,4 @@ -
+
@@ -73,7 +110,6 @@ window.__EnergyPieQueue = window.__EnergyPieQueue || []; window.__EnergyPieReady = false; - // Symcon ruft handleMessage evtl. sehr früh auf -> wir puffern. window.handleMessage = function (data) { window.__EnergyPieQueue.push(data); @@ -97,7 +133,7 @@ const elDbg = document.getElementById('dbg'); const elErr = document.getElementById('err'); - // Start nicht "grau/leer" + // Start nicht "leer" elGrid.innerHTML = '
Lade Daten…
'; // --- helpers --- @@ -133,11 +169,10 @@ elErr.textContent = 'JS-Fehler: ' + msg; } - // Global error trap window.addEventListener('error', (ev) => showErr(ev.error || ev.message)); window.addEventListener('unhandledrejection', (ev) => showErr(ev.reason)); - // --- requestAction robust finden (Popup hat das oft am parent) --- + // --- requestAction robust finden --- function getRequestAction() { if (typeof window.requestAction === 'function') return window.requestAction; if (typeof window.parent?.requestAction === 'function') return window.parent.requestAction; @@ -156,11 +191,10 @@ if (tryCall()) return; - // Popup/Fullscreen: manchmal kommt requestAction deutlich später -> länger retry let tries = 0; const timer = setInterval(() => { tries++; - if (tryCall() || tries >= 150) clearInterval(timer); // ~18s + if (tryCall() || tries >= 150) clearInterval(timer); }, 120); } @@ -169,64 +203,59 @@ } // --- donut card --- -function donutCard({ title, percent, subtitle, color }) { - const share = clamp01(percent / 100); - const r = 56; - const c = 2 * Math.PI * r; - const dash = share * c; - const gap = c - dash; + function donutCard({ title, percent, subtitle, color }) { + const share = clamp01(percent / 100); + const r = 56; + const c = 2 * Math.PI * r; + const dash = share * c; + const gap = c - dash; - return ` -
+ return ` +
- -
- ${escapeHtml(title)} -
+
+ ${escapeHtml(title)} +
- -
- - - - +
+ + + + - -
- ${escapeHtml(percent.toFixed(1))}% +
+ ${escapeHtml(percent.toFixed(1))}% +
+
+ +
+ ${escapeHtml(subtitle)}
- - -
- ${escapeHtml(subtitle)} -
-
- `; -} + `; + } function render(data) { const values = data?.values || {}; @@ -240,14 +269,12 @@ function donutCard({ title, percent, subtitle, color }) { const evq = (prod > 0) ? (eigenClamped / prod * 100) : 0; const autark = (cons > 0) ? (eigenClamped / cons * 100) : 0; - // Controls sync if (data?.range) elRange.value = data.range; if (data?.date) elDate.value = data.date; const isTotal = (data?.range === 'total'); elDate.disabled = isTotal; - // Zeitraum-Text if (data?.tStart && data?.tEnd) { const s = new Date(data.tStart * 1000); const e = new Date(data.tEnd * 1000); @@ -258,7 +285,6 @@ function donutCard({ title, percent, subtitle, color }) { elPeriod.textContent = ''; } - // Hint if (data?.hasData === false) { elHint.textContent = 'Keine Logdaten für den gewählten Zeitraum.'; } else { @@ -281,6 +307,8 @@ function donutCard({ title, percent, subtitle, color }) { }) ].join(''); + elDbg.textContent = `Letzte Daten: ${new Date().toLocaleTimeString()} · range=${data?.range ?? '-'} · date=${data?.date ?? '-'}`; + elErr.textContent = ''; } // --- cache --- @@ -296,7 +324,6 @@ function donutCard({ title, percent, subtitle, color }) { } } - // 2) Consumer für gepufferte Symcon-Messages window.__EnergyPieConsume = function (data) { if (typeof data === 'string') { try { data = JSON.parse(data); } catch(e) {} @@ -321,18 +348,15 @@ function donutCard({ title, percent, subtitle, color }) { elToday.addEventListener('click', () => safeRequestAction('Today', 1)); elNext.addEventListener('click', () => safeRequestAction('Next', 1)); - // On load: cached sofort rendern const cached = loadLast(); if (cached) render(cached); - // UI ready -> Queue flushen window.__EnergyPieReady = true; if (window.__EnergyPieQueue && window.__EnergyPieQueue.length) { const q = window.__EnergyPieQueue.splice(0); q.forEach(d => window.__EnergyPieConsume(d)); } - // Refresh on start + on fullscreen/resize/visibility changes safeRefreshSoon(); document.addEventListener('visibilitychange', () => {