thermostat working

This commit is contained in:
2025-11-06 11:53:35 +01:00
parent cb555a1f67
commit e28633cb9a
6 changed files with 555 additions and 5 deletions

View File

@@ -523,6 +523,7 @@
let eventSource = null;
let currentState = {};
let thermostatTargets = {};
let thermostatModes = {};
// Initialize device states
{% for room in rooms %}
@@ -531,6 +532,7 @@
currentState['{{ device.device_id }}'] = 'off';
{% elif device.type == "thermostat" %}
thermostatTargets['{{ device.device_id }}'] = 21.0;
thermostatModes['{{ device.device_id }}'] = 'off';
{% endif %}
{% endfor %}
{% endfor %}
@@ -606,6 +608,7 @@
// Adjust thermostat target temperature
async function adjustTarget(deviceId, delta) {
const currentTarget = thermostatTargets[deviceId] || 21.0;
const currentMode = thermostatModes[deviceId] || 'off';
const newTarget = Math.max(5.0, Math.min(30.0, currentTarget + delta));
try {
@@ -617,6 +620,7 @@
body: JSON.stringify({
type: 'thermostat',
payload: {
mode: currentMode,
target: newTarget
}
})
@@ -725,8 +729,11 @@
thermostatTargets[deviceId] = target;
}
if (mode !== undefined && modeSpan) {
modeSpan.textContent = mode.toUpperCase();
if (mode !== undefined) {
if (modeSpan) {
modeSpan.textContent = mode.toUpperCase();
}
thermostatModes[deviceId] = mode;
// Update mode button states
['off', 'heat', 'auto'].forEach(m => {