diff --git a/Energy_Pie/module.php b/Energy_Pie/module.php index 786f93d..dfa579a 100644 --- a/Energy_Pie/module.php +++ b/Energy_Pie/module.php @@ -108,13 +108,9 @@ private function RecalculateAndPush(): void $dbgFeed = []; $dbgGrid = []; - $prodVar = $this->ReadPropertyInteger('VarProduction'); - $feedVar = $this->ReadPropertyInteger('VarFeedIn'); - $gridVar = $this->ReadPropertyInteger('VarGrid'); - - $prod = $this->readDelta($prodVar, $tStart, $tEnd, $dbgProd); - $feed = $this->readDelta($feedVar, $tStart, $tEnd, $dbgFeed); - $grid = $this->readDelta($gridVar, $tStart, $tEnd, $dbgGrid); + $prod = $this->readDelta($this->ReadPropertyInteger('VarProduction'), $tStart, $tEnd, $dbgProd); + $feed = $this->readDelta($this->ReadPropertyInteger('VarFeedIn'), $tStart, $tEnd, $dbgFeed); + $grid = $this->readDelta($this->ReadPropertyInteger('VarGrid'), $tStart, $tEnd, $dbgGrid); $house = $prod - $feed + $grid; if ($house < 0) $house = 0.0; @@ -187,16 +183,16 @@ private function RecalculateAndPush(): void } - private function readDelta(int $varId, int $tStart, int $tEnd, array &$dbg): float + private function readDelta(int $varId, int $tStart, int $tEnd, array &$dbg): float { $dbg = [ - 'varId' => $varId, + 'varId' => $varId, 'archiveId' => 0, - 'count' => 0, - 'first' => null, - 'last' => null, - 'vStart' => null, - 'vEnd' => null + 'count' => 0, + 'first' => null, + 'last' => null, + 'vStart' => null, + 'vEnd' => null ]; if ($varId <= 0 || !IPS_VariableExists($varId)) { @@ -219,26 +215,18 @@ private function RecalculateAndPush(): void $dbg['count'] = count($values); $dbg['first'] = (float)$values[0]['Value']; - $dbg['last'] = (float)$values[count($values)-1]['Value']; + $dbg['last'] = (float)$values[count($values) - 1]['Value']; $vStart = null; $vEnd = null; foreach ($values as $v) { $ts = (int)$v['TimeStamp']; - - if ($ts <= $tStart) { - $vStart = (float)$v['Value']; - } - if ($ts <= $tEnd) { - $vEnd = (float)$v['Value']; - } - if ($ts > $tEnd) { - break; - } + if ($ts <= $tStart) $vStart = (float)$v['Value']; + if ($ts <= $tEnd) $vEnd = (float)$v['Value']; + if ($ts > $tEnd) break; } - // Wenn kein Wert vor Start/Ende gefunden wurde, nimm ersten/letzten im Fenster if ($vStart === null) $vStart = $dbg['first']; if ($vEnd === null) $vEnd = $dbg['last']; @@ -250,6 +238,8 @@ private function RecalculateAndPush(): void } + + /** * Buttons for quick navigation. */