From 0cb1fc635e0ebce44169739c0b15a8ca339d6025 Mon Sep 17 00:00:00 2001 From: Moirtz Wagner Date: Mon, 31 Aug 2026 13:32:58 +0200 Subject: [PATCH] Etage ist Pflicht Die Auswahlliste im Editor bot ein "-" an. Eine Automatik ohne Etage taucht aber in keinem der drei Reiter auf und ist danach nur noch in der Datenbank zu finden - anlegen und sofort verlieren. Der Eintrag ist weg, und der Zustand ist jetzt an drei Stellen unmoeglich statt nur unwahrscheinlich: die Liste kennt nur noch OG, EG und UG, saveAutomation lehnt alles andere mit einer Meldung ab statt still auf "" zurueckzufallen, und im Enum der Spalte gibt es den leeren Wert nicht mehr. Die Reihenfolge in der Liste ist jetzt OG, EG, UG wie bei den Reitern - damit trifft der Rueckfall auf den ersten Eintrag dieselbe Etage wie die Startseite. Kennt die Liste die Etage eines Datensatzes nicht, faellt sie darauf zurueck, statt leer stehen zu bleiben und beim Speichern "" zu schicken. Co-Authored-By: Claude Opus 5 --- ajax/AutoAction.php | 9 ++++++--- homeMesh_automations.sql | 2 +- js/solar/autoActionFuncs.js | 9 ++++++++- restricted/automations.php | 10 +++++++--- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ajax/AutoAction.php b/ajax/AutoAction.php index fcbcf38..39ec23c 100644 --- a/ajax/AutoAction.php +++ b/ajax/AutoAction.php @@ -155,11 +155,14 @@ $nutzdaten = json_encode([
+
diff --git a/homeMesh_automations.sql b/homeMesh_automations.sql index dca92a2..e4d6178 100644 --- a/homeMesh_automations.sql +++ b/homeMesh_automations.sql @@ -29,7 +29,7 @@ SET NAMES utf8mb4; CREATE TABLE IF NOT EXISTS `automations` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL COMMENT 'Anzeigename, z.B. Kinder zu', - `floor` enum('','UG','EG','OG') NOT NULL DEFAULT '' COMMENT 'Reiter in der Uebersicht', + `floor` enum('UG','EG','OG') NOT NULL DEFAULT 'OG' COMMENT 'Reiter in der Uebersicht. Ohne Etage waere die Automatik in keinem davon zu sehen, deshalb gibt es keinen leeren Wert', `enabled` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Aktiv oder pausiert', `window_from` time NOT NULL DEFAULT '00:00:00' COMMENT 'Aktiver Zeitraum, Beginn', `window_to` time NOT NULL DEFAULT '23:59:00' COMMENT 'Aktiver Zeitraum, Ende. Kleiner als window_from = ueber Mitternacht', diff --git a/js/solar/autoActionFuncs.js b/js/solar/autoActionFuncs.js index 81b8523..90acba0 100644 --- a/js/solar/autoActionFuncs.js +++ b/js/solar/autoActionFuncs.js @@ -373,7 +373,14 @@ function fuelleFormular() { optionListe(sperre, autoLockouts.map(o => ({ value: o.value, text: o.label })), autoModel.lockout_secs); document.getElementById("autoName").value = autoModel.name; - document.getElementById("autoFloor").value = autoModel.floor; + // Kennt die Liste die Etage nicht, bleibt eine Auswahlliste sonst leer + // stehen und schickt beim Speichern "" mit. + const etage = document.getElementById("autoFloor"); + etage.value = autoModel.floor; + if (etage.selectedIndex < 0) { + etage.selectedIndex = 0; + autoModel.floor = etage.value; + } document.getElementById("tSpanFrom").value = autoModel.window_from; document.getElementById("tSpanTo").value = autoModel.window_to; document.getElementById("actFerien").checked = autoModel.on_vacation; diff --git a/restricted/automations.php b/restricted/automations.php index d8c9f76..4a4171e 100644 --- a/restricted/automations.php +++ b/restricted/automations.php @@ -267,7 +267,9 @@ function emptyAutomation($floor) return [ "id" => 0, "name" => "", - "floor" => $floor, + // Aufgerufen wird der Editor immer aus einem Etagenreiter. Fehlt die + // Angabe trotzdem, gilt dieselbe Etage wie auf der Startseite. + "floor" => in_array($floor, ["UG", "EG", "OG"], true) ? $floor : "OG", "enabled" => true, "window_from" => "00:00", "window_to" => "23:59", @@ -370,8 +372,10 @@ function saveAutomation($data) throw new InvalidArgumentException("Bitte einen Namen vergeben."); } $floor = strval($data["floor"] ?? ""); - if (!in_array($floor, ["", "UG", "EG", "OG"], true)) { - $floor = ""; + if (!in_array($floor, ["UG", "EG", "OG"], true)) { + // Nicht stillschweigend auf "" zurueckfallen: die Automatik wuerde + // dann in keinem der drei Reiter mehr auftauchen. + throw new InvalidArgumentException("Bitte eine Etage wählen."); } $conditions = is_array($data["conditions"] ?? null) ? $data["conditions"] : []; $actions = is_array($data["actions"] ?? null) ? $data["actions"] : [];