fix error for devices with missing state
This commit is contained in:
@@ -358,6 +358,7 @@
|
|||||||
let deviceData = null;
|
let deviceData = null;
|
||||||
let deviceState = {};
|
let deviceState = {};
|
||||||
let roomName = '';
|
let roomName = '';
|
||||||
|
let deviceStateUnknown = false;
|
||||||
|
|
||||||
// Device type icons
|
// Device type icons
|
||||||
const deviceIcons = {
|
const deviceIcons = {
|
||||||
@@ -380,8 +381,19 @@
|
|||||||
// NEW: Use new endpoints for device info and layout
|
// NEW: Use new endpoints for device info and layout
|
||||||
deviceData = await window.apiClient.getDevice(deviceId);
|
deviceData = await window.apiClient.getDevice(deviceId);
|
||||||
console.log("Loaded device data:", deviceData);
|
console.log("Loaded device data:", deviceData);
|
||||||
|
|
||||||
|
try {
|
||||||
deviceState = await window.apiClient.getDeviceState(deviceId);
|
deviceState = await window.apiClient.getDeviceState(deviceId);
|
||||||
console.log("Loaded device state:", deviceState);
|
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);
|
const layoutInfo = await window.apiClient.getDeviceLayout(deviceId);
|
||||||
console.log("Loaded layout info:", layoutInfo);
|
console.log("Loaded layout info:", layoutInfo);
|
||||||
roomName = layoutInfo.room;
|
roomName = layoutInfo.room;
|
||||||
@@ -517,6 +529,14 @@
|
|||||||
}, 0);
|
}, 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);
|
container.appendChild(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,6 +572,14 @@
|
|||||||
`;
|
`;
|
||||||
card.appendChild(sliderGroup);
|
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);
|
container.appendChild(card);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -580,6 +608,14 @@
|
|||||||
powerGroup.appendChild(powerButton);
|
powerGroup.appendChild(powerButton);
|
||||||
card.appendChild(powerGroup);
|
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);
|
container.appendChild(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -598,6 +634,14 @@
|
|||||||
`;
|
`;
|
||||||
card.appendChild(statusDiv);
|
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);
|
container.appendChild(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user