no message
This commit is contained in:
@@ -29,10 +29,29 @@
|
|||||||
gap:14px;max-width:880px;">
|
gap:14px;max-width:880px;">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Fehler/Status sichtbar machen (damit es nicht einfach "leer" ist) -->
|
<!-- Debug/Status -->
|
||||||
<div id="err" style="margin-top:10px;font-size:12px;opacity:0.8;color:#ffb4b4;"></div>
|
<div id="dbg" style="margin-top:10px;font-size:12px;opacity:0.75;"></div>
|
||||||
|
|
||||||
|
<!-- Fehler -->
|
||||||
|
<div id="err" style="margin-top:6px;font-size:12px;opacity:0.9;color:#ffb4b4;"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 1) Puffer-Handler: fängt Symcon-Messages ab, selbst wenn UI noch nicht ready ist -->
|
||||||
|
<script>
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (window.__EnergyPieReady && typeof window.__EnergyPieConsume === "function") {
|
||||||
|
const q = window.__EnergyPieQueue.splice(0);
|
||||||
|
q.forEach(d => window.__EnergyPieConsume(d));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
(function () {
|
(function () {
|
||||||
const elRange = document.getElementById('range');
|
const elRange = document.getElementById('range');
|
||||||
@@ -43,8 +62,12 @@
|
|||||||
const elPeriod = document.getElementById('period');
|
const elPeriod = document.getElementById('period');
|
||||||
const elHint = document.getElementById('hint');
|
const elHint = document.getElementById('hint');
|
||||||
const elGrid = document.getElementById('grid');
|
const elGrid = document.getElementById('grid');
|
||||||
|
const elDbg = document.getElementById('dbg');
|
||||||
const elErr = document.getElementById('err');
|
const elErr = document.getElementById('err');
|
||||||
|
|
||||||
|
// Start nicht "grau/leer"
|
||||||
|
elGrid.innerHTML = '<div style="opacity:.75;padding:12px;">Lade Daten…</div>';
|
||||||
|
|
||||||
// --- helpers ---
|
// --- helpers ---
|
||||||
function toNum(x) {
|
function toNum(x) {
|
||||||
const n = Number(x);
|
const n = Number(x);
|
||||||
@@ -73,11 +96,27 @@
|
|||||||
return `${dd}.${mm}.${yyyy} ${hh}:${mi}`;
|
return `${dd}.${mm}.${yyyy} ${hh}:${mi}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- make requestAction safe (wait until available) ---
|
function showErr(e) {
|
||||||
|
const msg = (e && e.message) ? e.message : String(e);
|
||||||
|
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) ---
|
||||||
|
function getRequestAction() {
|
||||||
|
if (typeof window.requestAction === 'function') return window.requestAction;
|
||||||
|
if (typeof window.parent?.requestAction === 'function') return window.parent.requestAction;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function safeRequestAction(ident, value) {
|
function safeRequestAction(ident, value) {
|
||||||
const tryCall = () => {
|
const tryCall = () => {
|
||||||
if (typeof requestAction === 'function') {
|
const ra = getRequestAction();
|
||||||
try { requestAction(ident, value); } catch (e) { showErr(e); }
|
if (ra) {
|
||||||
|
try { ra(ident, value); } catch (e) { showErr(e); }
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -85,11 +124,11 @@
|
|||||||
|
|
||||||
if (tryCall()) return;
|
if (tryCall()) return;
|
||||||
|
|
||||||
// retry a few times (fullscreen reload timing)
|
// Popup/Fullscreen: manchmal kommt requestAction deutlich später -> länger retry
|
||||||
let tries = 0;
|
let tries = 0;
|
||||||
const timer = setInterval(() => {
|
const timer = setInterval(() => {
|
||||||
tries++;
|
tries++;
|
||||||
if (tryCall() || tries >= 25) clearInterval(timer);
|
if (tryCall() || tries >= 150) clearInterval(timer); // ~18s
|
||||||
}, 120);
|
}, 120);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,15 +136,6 @@
|
|||||||
setTimeout(() => safeRequestAction('Refresh', 1), 150);
|
setTimeout(() => safeRequestAction('Refresh', 1), 150);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showErr(e) {
|
|
||||||
const msg = (e && e.message) ? e.message : String(e);
|
|
||||||
elErr.textContent = 'JS-Fehler: ' + msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Global error trap (damit wir sehen, wenn’s crasht)
|
|
||||||
window.addEventListener('error', (ev) => showErr(ev.error || ev.message));
|
|
||||||
window.addEventListener('unhandledrejection', (ev) => showErr(ev.reason));
|
|
||||||
|
|
||||||
// --- donut card ---
|
// --- donut card ---
|
||||||
function donutCard({ title, percent, subtitle, color }) {
|
function donutCard({ title, percent, subtitle, color }) {
|
||||||
const share = clamp01(percent / 100);
|
const share = clamp01(percent / 100);
|
||||||
@@ -148,10 +178,10 @@
|
|||||||
function render(data) {
|
function render(data) {
|
||||||
const values = data?.values || {};
|
const values = data?.values || {};
|
||||||
const prod = toNum(values?.Produktion);
|
const prod = toNum(values?.Produktion);
|
||||||
const cons = toNum(values?.Hausverbrauch); // Verbrauch
|
const cons = toNum(values?.Hausverbrauch);
|
||||||
const grid = toNum(values?.Netz); // Netzbezug
|
const grid = toNum(values?.Netz);
|
||||||
|
|
||||||
const eigen = cons - grid; // Eigenverbrauch
|
const eigen = cons - grid;
|
||||||
const eigenClamped = eigen < 0 ? 0 : eigen;
|
const eigenClamped = eigen < 0 ? 0 : eigen;
|
||||||
|
|
||||||
const evq = (prod > 0) ? (eigenClamped / prod * 100) : 0;
|
const evq = (prod > 0) ? (eigenClamped / prod * 100) : 0;
|
||||||
@@ -198,10 +228,11 @@
|
|||||||
})
|
})
|
||||||
].join('');
|
].join('');
|
||||||
|
|
||||||
elErr.textContent = ''; // clear errors if render succeeded
|
elDbg.textContent = `Letzte Daten: ${new Date().toLocaleTimeString()} · range=${data?.range ?? '-'} · date=${data?.date ?? '-'}`;
|
||||||
|
elErr.textContent = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- cache last payload so fullscreen reload still shows something immediately ---
|
// --- cache ---
|
||||||
function saveLast(data) {
|
function saveLast(data) {
|
||||||
try { sessionStorage.setItem('EnergyPie_last', JSON.stringify(data)); } catch(e) {}
|
try { sessionStorage.setItem('EnergyPie_last', JSON.stringify(data)); } catch(e) {}
|
||||||
}
|
}
|
||||||
@@ -214,8 +245,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Symcon -> Tile
|
// 2) Consumer für gepufferte Symcon-Messages
|
||||||
window.handleMessage = function (data) {
|
window.__EnergyPieConsume = function (data) {
|
||||||
if (typeof data === 'string') {
|
if (typeof data === 'string') {
|
||||||
try { data = JSON.parse(data); } catch(e) {}
|
try { data = JSON.parse(data); } catch(e) {}
|
||||||
}
|
}
|
||||||
@@ -224,7 +255,7 @@
|
|||||||
render(data);
|
render(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
// UI events (safe)
|
// UI events
|
||||||
elRange.addEventListener('change', () => safeRequestAction('SetRange', elRange.value));
|
elRange.addEventListener('change', () => safeRequestAction('SetRange', elRange.value));
|
||||||
|
|
||||||
let dateTimer = null;
|
let dateTimer = null;
|
||||||
@@ -239,10 +270,17 @@
|
|||||||
elToday.addEventListener('click', () => safeRequestAction('Today', 1));
|
elToday.addEventListener('click', () => safeRequestAction('Today', 1));
|
||||||
elNext.addEventListener('click', () => safeRequestAction('Next', 1));
|
elNext.addEventListener('click', () => safeRequestAction('Next', 1));
|
||||||
|
|
||||||
// On load: render cached immediately, then refresh when ready
|
// On load: cached sofort rendern
|
||||||
const cached = loadLast();
|
const cached = loadLast();
|
||||||
if (cached) render(cached);
|
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
|
// Refresh on start + on fullscreen/resize/visibility changes
|
||||||
safeRefreshSoon();
|
safeRefreshSoon();
|
||||||
|
|
||||||
@@ -250,15 +288,8 @@
|
|||||||
if (!document.hidden) safeRefreshSoon();
|
if (!document.hidden) safeRefreshSoon();
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('resize', () => {
|
window.addEventListener('resize', () => safeRefreshSoon());
|
||||||
// some Symcon fullscreen transitions trigger resize + reload timing
|
window.addEventListener('pageshow', () => safeRefreshSoon());
|
||||||
safeRefreshSoon();
|
|
||||||
});
|
|
||||||
|
|
||||||
// pageshow covers some "recreated webview" cases
|
|
||||||
window.addEventListener('pageshow', () => {
|
|
||||||
safeRefreshSoon();
|
|
||||||
});
|
|
||||||
|
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user