From db5e4589d0812145a0536758c1c073ab0175eda1 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Mon, 1 Dec 2025 14:48:32 +0100 Subject: [PATCH] fix error for devices with missing state --- apps/ui/templates/device.html | 48 +++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/apps/ui/templates/device.html b/apps/ui/templates/device.html index 4892f2c..035a205 100644 --- a/apps/ui/templates/device.html +++ b/apps/ui/templates/device.html @@ -358,6 +358,7 @@ let deviceData = null; let deviceState = {}; let roomName = ''; + let deviceStateUnknown = false; // Device type icons const deviceIcons = { @@ -380,8 +381,19 @@ // NEW: Use new endpoints for device info and layout deviceData = await window.apiClient.getDevice(deviceId); console.log("Loaded device data:", deviceData); - deviceState = await window.apiClient.getDeviceState(deviceId); - console.log("Loaded device state:", deviceState); + + try { + deviceState = await window.apiClient.getDeviceState(deviceId); + console.log("Loaded device state:", deviceState); + if (!deviceState || Object.keys(deviceState).length === 0) { + deviceStateUnknown = true; + deviceState = {}; + } + } catch (stateError) { + console.warn('No state for device, using unknown state:', stateError); + deviceStateUnknown = true; + deviceState = {}; + } const layoutInfo = await window.apiClient.getDeviceLayout(deviceId); console.log("Loaded layout info:", layoutInfo); roomName = layoutInfo.room; @@ -517,6 +529,14 @@ }, 0); } + if (deviceStateUnknown) { + const hint = document.createElement('div'); + hint.className = 'device-meta'; + hint.style.marginTop = '12px'; + hint.textContent = 'Status unbekannt'; + card.appendChild(hint); + } + container.appendChild(card); } @@ -552,6 +572,14 @@ `; card.appendChild(sliderGroup); + if (deviceStateUnknown) { + const hint = document.createElement('div'); + hint.className = 'device-meta'; + hint.style.marginTop = '12px'; + hint.textContent = 'Status unbekannt'; + card.appendChild(hint); + } + container.appendChild(card); setTimeout(() => { @@ -580,6 +608,14 @@ powerGroup.appendChild(powerButton); card.appendChild(powerGroup); + if (deviceStateUnknown) { + const hint = document.createElement('div'); + hint.className = 'device-meta'; + hint.style.marginTop = '12px'; + hint.textContent = 'Status unbekannt'; + card.appendChild(hint); + } + container.appendChild(card); } @@ -598,6 +634,14 @@ `; card.appendChild(statusDiv); + if (deviceStateUnknown) { + const hint = document.createElement('div'); + hint.className = 'device-meta'; + hint.style.marginTop = '12px'; + hint.textContent = 'Status unbekannt'; + card.appendChild(hint); + } + container.appendChild(card); }