From 47bf00622971a8007cf7961bcf114483d431714e Mon Sep 17 00:00:00 2001 From: DanielHaefliger Date: Thu, 11 Dec 2025 14:13:08 +0100 Subject: [PATCH] no message --- Abrechnung/module.php | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/Abrechnung/module.php b/Abrechnung/module.php index d253413..3e6edb9 100644 --- a/Abrechnung/module.php +++ b/Abrechnung/module.php @@ -635,24 +635,34 @@ foreach ($meters as $name => $mm) { return $closest ?? (float)GetValue($varId); } - private function getDeltaFromArchive(int $varId, int $tStart, int $tEnd): float - { - // Beide Werte: immer letzter geloggter Wert VOR/GENAU zum Zeitpunkt - $startValue = $this->GetValueAt($varId, $tStart, false); - $endValue = $this->GetValueAt($varId, $tEnd, false); +private function getDeltaFromArchive(int $varId, int $tStart, int $tEnd): float +{ + // Werte holen + $startValue = $this->GetValueAt($varId, $tStart, false); + $endValue = $this->GetValueAt($varId, $tEnd, false); - if ($startValue === null || $endValue === null) { - return 0.0; - } + // --- Logging --- + IPS_LogMessage("KostenModul", "getDeltaFromArchive(varId=$varId)"); + IPS_LogMessage("KostenModul", " Startzeit: " . date('Y-m-d H:i:s', $tStart) . " | Startwert: " . var_export($startValue, true)); + IPS_LogMessage("KostenModul", " Endzeit: " . date('Y-m-d H:i:s', $tEnd) . " | Endwert: " . var_export($endValue, true)); - $diff = $endValue - $startValue; - if ($diff < 0) { - // Sicherheitsnetz bei Zähler-Reset - $diff = 0.0; - } - return (float)$diff; + if ($startValue === null || $endValue === null) { + IPS_LogMessage("KostenModul", " -> Einer der Werte ist NULL, Delta = 0.0"); + return 0.0; } + // Delta berechnen + $diff = $endValue - $startValue; + + if ($diff < 0) { + IPS_LogMessage("KostenModul", " WARNUNG: Negatives Delta erkannt! Zähler wurde vermutlich zurückgesetzt. Delta wird auf 0 gesetzt."); + $diff = 0.0; + } + + IPS_LogMessage("KostenModul", " Delta = $diff"); + return (float)$diff; +} + private function toUnixTs($val, $endOfDay = false) { if (is_int($val)) {