This commit is contained in:
Mateusz Gruszczyński
2026-09-01 10:20:19 +02:00
parent 1a5c1305dc
commit 3479ed750d
34 changed files with 575 additions and 113 deletions
+22 -3
View File
@@ -46,20 +46,37 @@ function updateDevice(device) {
if (index >= 0) app.devices[index] = device; else app.devices.push(device);
}
function enqueueZoneControlRequest(id, patch) {
const previous = app.zoneControlQueue[id] || Promise.resolve();
const request = previous.catch(() => {}).then(() =>
api(`/api/zones/${encodeURIComponent(id)}/control`, {method:'POST', body:patch})
);
app.zoneControlQueue[id] = request;
request.finally(() => {
if (app.zoneControlQueue[id] === request) delete app.zoneControlQueue[id];
}).catch(() => {});
return request;
}
async function sendZoneLocalPower(id, power) {
const sequence = (app.zoneControlSeq[id] || 0) + 1;
app.zoneControlSeq[id] = sequence;
try {
const zone = await api(`/api/zones/${encodeURIComponent(id)}/control`, {method:'POST', body:{power}});
const zone = await enqueueZoneControlRequest(id, {power});
if (app.zoneControlSeq[id] !== sequence) return;
const index = app.zones.findIndex(item => item.id === zone.id);
if (index >= 0) app.zones[index] = zone; else app.zones.push(zone);
renderAll(); scheduleControlPlanLoad(); toast(tr('zones.localPowerUpdated'));
} catch (error) { toast(error.message, true); }
} catch (error) {
if (app.zoneControlSeq[id] === sequence) { await loadBootstrap(); toast(error.message, true); }
}
}
async function sendZoneControl(id, patch) {
const sequence = (app.zoneControlSeq[id] || 0) + 1;
app.zoneControlSeq[id] = sequence;
try {
const zone = await api(`/api/zones/${encodeURIComponent(id)}/control`, {method:'POST', body:patch});
const zone = await enqueueZoneControlRequest(id, patch);
if (app.zoneControlSeq[id] !== sequence) return;
const index = app.zones.findIndex(item => item.id === zone.id);
if (index >= 0) app.zones[index] = zone; else app.zones.push(zone);
@@ -69,6 +86,7 @@ async function sendZoneControl(id, patch) {
}
}
function queueZoneTemperature(zone, value, {snapToHalf=true}={}) {
const clamped = clamp(value, 8, 30);
const next = snapToHalf ? Math.round(clamped * 2) / 2 : Math.round(clamped * 10) / 10;
@@ -93,6 +111,7 @@ function beginInlineTemperatureEdit(target) {
input.inputMode = 'decimal';
input.value = value.toFixed(decimals);
input.setAttribute('aria-label', tr('common.targetTemperature'));
input.title = tr('common.targetTemperature');
target.classList.add('editing');
target.replaceChildren(input);
input.focus();