-
-
- ${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', () => {