diff --git a/ajax/AutoAction.php b/ajax/AutoAction.php index 40cb677..c582852 100644 --- a/ajax/AutoAction.php +++ b/ajax/AutoAction.php @@ -232,7 +232,7 @@ if ($action === "list") { // die Bedingung stehen bleiben, dann wird ausgeloest. if (!empty($a["hold_secs"])) { $wann .= ", erst nach " - . intdiv($a["hold_secs"], 60) . " Min. ununterbrochen"; + . haltezeitKurz($a["hold_secs"]) . " ununterbrochen"; } if ($a["lockout_secs"] > 0) { $wann .= ", frühestens alle " diff --git a/js/solar/autoActionFuncs.js b/js/solar/autoActionFuncs.js index 4279a00..565ae9a 100644 --- a/js/solar/autoActionFuncs.js +++ b/js/solar/autoActionFuncs.js @@ -1126,9 +1126,7 @@ function rahmenKurzText() { teile.push(autoModel.window_from === "00:00" && autoModel.window_to === "23:59" ? "rund um die Uhr" : autoModel.window_from + "–" + autoModel.window_to); - if (autoModel.hold_secs > 0) { - teile.push("erst nach " + Math.floor(autoModel.hold_secs / 60) + " Min."); - } + if (autoModel.hold_secs > 0) teile.push("erst nach " + haltezeitKurz(autoModel.hold_secs)); if (autoModel.lockout_secs > 0) { teile.push("Sperre " + (autoModel.lockout_secs >= 60 ? Math.floor(autoModel.lockout_secs / 60) + " Min." @@ -1139,6 +1137,12 @@ function rahmenKurzText() { return teile.join(" · "); } +/** Wie haltezeitKurz() in automations.php: Minuten bis eine Stunde, dann Stunden. */ +function haltezeitKurz(sekunden) { + if (sekunden < 3600) return Math.floor(sekunden / 60) + " Min."; + return (sekunden / 3600).toFixed(1).replace(/[.,]0$/, "").replace(".", ",") + " Std."; +} + function rahmenIstVorgabe() { return autoModel.weekdays === 127 && autoModel.on_vacation === 1 diff --git a/restricted/automations.php b/restricted/automations.php index ce3aae8..b9d2397 100644 --- a/restricted/automations.php +++ b/restricted/automations.php @@ -226,14 +226,35 @@ function lockoutChoices() */ function haltezeitChoices() { - return [ - ["value" => 0, "label" => "sofort"], - ["value" => 300, "label" => "nach 5 Min. ununterbrochen"], - ["value" => 900, "label" => "nach 15 Min. ununterbrochen"], - ["value" => 1800, "label" => "nach 30 Min. ununterbrochen"], - ["value" => 3600, "label" => "nach 1 Std. ununterbrochen"], - ["value" => 10800, "label" => "nach 3 Std. ununterbrochen"], - ]; + // Die 3,5 Stunden fallen aus der Reihe, weil sie aus einem konkreten Fall + // stammen: dauerhafter Wasserverbrauch. Kuerzer waere Fehlalarm (eine + // lange Dusche, eine Waschmaschine), laenger liefe ein offener Hahn eine + // halbe Nacht. + $stufen = [0, 300, 900, 1800, 3600, 7200, 12600]; + $aus = []; + foreach ($stufen as $sek) { + $aus[] = [ + "value" => $sek, + "label" => $sek ? "nach " . haltezeitKurz($sek) . " ununterbrochen" : "sofort", + ]; + } + return $aus; +} + +/** + * Eine Haltezeit in Worten - "45 Min.", "1 Std.", "3,5 Std." + * + * Minuten bis eine Stunde, darueber Stunden: "210 Min." muss man umrechnen, + * "3,5 Std." nicht. Die Nachkommastelle faellt weg, wenn sie null ist. + */ +function haltezeitKurz($sekunden) +{ + $sekunden = intval($sekunden); + if ($sekunden < 3600) { + return intdiv($sekunden, 60) . " Min."; + } + $zahl = number_format($sekunden / 3600, 1, ",", ""); + return rtrim(rtrim($zahl, "0"), ",") . " Std."; } /**