sse iphone fix 4
This commit is contained in:
@@ -1161,21 +1161,23 @@
|
||||
// Load initial device states
|
||||
async function loadDevices() {
|
||||
try {
|
||||
const response = await fetch(api('/devices'));
|
||||
const devices = await response.json();
|
||||
console.log('Loaded initial device states:', devices);
|
||||
const response = await fetch(api('/devices/states'));
|
||||
const states = await response.json();
|
||||
console.log('Loaded initial device states:', states);
|
||||
|
||||
// Update UI with initial states
|
||||
devices.forEach(device => {
|
||||
if (device.type === 'light' && device.state) {
|
||||
currentState[device.id] = device.state.power;
|
||||
updateDeviceUI(device.id, device.state.power, device.state.brightness);
|
||||
} else if (device.type === 'thermostat' && device.state) {
|
||||
if (device.state.mode) thermostatModes[device.id] = device.state.mode;
|
||||
if (device.state.target) thermostatTargets[device.id] = device.state.target;
|
||||
updateThermostatUI(device.id, device.state.current, device.state.target, device.state.mode);
|
||||
for (const [deviceId, state] of Object.entries(states)) {
|
||||
if (state.power !== undefined) {
|
||||
// It's a light
|
||||
currentState[deviceId] = state.power;
|
||||
updateDeviceUI(deviceId, state.power, state.brightness);
|
||||
} else if (state.mode !== undefined || state.target !== undefined) {
|
||||
// It's a thermostat
|
||||
if (state.mode) thermostatModes[deviceId] = state.mode;
|
||||
if (state.target) thermostatTargets[deviceId] = state.target;
|
||||
updateThermostatUI(deviceId, state.current, state.target, state.mode);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load initial device states:', error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user