fix error for devices with missing state
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user