This commit is contained in:
Mateusz Gruszczyński
2026-09-01 11:10:28 +02:00
parent 3479ed750d
commit 9f08d7ccf9
30 changed files with 559 additions and 150 deletions
+22 -2
View File
@@ -34,11 +34,31 @@ function showHistoryTab(tab, {push=true, load=true}={}) {
if (load) loadHistory();
}
async function sendDeviceCommand(id, command) {
async function sendDeviceCommand(id, commandOrFactory) {
const previous = app.deviceControlQueue[id] || Promise.resolve();
const request = previous.catch(() => {}).then(() => {
const current = app.devices.find(device => device.id === id);
const command = typeof commandOrFactory === 'function' ? commandOrFactory(current) : commandOrFactory;
return api(`/api/devices/${encodeURIComponent(id)}/command`, {method:'POST', body:command});
});
app.deviceControlQueue[id] = request;
try {
const device = await api(`/api/devices/${encodeURIComponent(id)}/command`, {method:'POST', body:command});
const device = await request;
updateDevice(device); renderAll();
} catch (error) { toast(error.message, true); }
finally {
if (app.deviceControlQueue[id] === request) delete app.deviceControlQueue[id];
}
}
function enqueueClimateControlTask(task) {
const previous = app.climateControlQueue || Promise.resolve();
const request = previous.catch(() => {}).then(task);
app.climateControlQueue = request;
request.finally(() => {
if (app.climateControlQueue === request) app.climateControlQueue = null;
}).catch(() => {});
return request;
}
function updateDevice(device) {