Version von testing eingefügt, scroll liste entfernt undkleine Bugsbehoben
This commit is contained in:
+31
-21
@@ -35,7 +35,7 @@ class Energy_Pie extends IPSModule
|
||||
}
|
||||
// Fullscreen-Fix: push periodically (adjust as you like)
|
||||
// 2000ms = alle 2 Sekunden (stabil, aber nicht ganz so brutal wie 1000ms)
|
||||
$this->SetTimerInterval('AutoPush', 2000);
|
||||
$this->SetTimerInterval('AutoPush', 60000);
|
||||
$this->RecalculateAndPush();
|
||||
}
|
||||
public function GetVisualizationTile(): string
|
||||
@@ -59,7 +59,7 @@ class Energy_Pie extends IPSModule
|
||||
break;
|
||||
case 'SetDate':
|
||||
$date = (string)$Value;
|
||||
if (!$this->isValidDate($date)) {
|
||||
if (!$this->isValidDate($date) || strtotime($date . ' 00:00:00') > time()) {
|
||||
return;
|
||||
}
|
||||
$this->WriteAttributeString(self::ATTR_DATE, $date);
|
||||
@@ -90,8 +90,17 @@ class Energy_Pie extends IPSModule
|
||||
$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);
|
||||
$hasData = (($dbgProd['count'] ?? 0) > 0) || (($dbgFeed['count'] ?? 0) > 0) || (($dbgGrid['count'] ?? 0) > 0);
|
||||
$noDataHint = (!$hasData && $range !== 'total') ? 'Letzter Zeitpunkt' : '';
|
||||
$hasData = (($dbgProd['inRange'] ?? 0) > 0) || (($dbgFeed['inRange'] ?? 0) > 0) || (($dbgGrid['inRange'] ?? 0) > 0);
|
||||
$lastLogTs = 0;
|
||||
if (!$hasData && $range !== 'total') {
|
||||
$lastLogTs = max(
|
||||
$this->getLastLogTimestamp($this->ReadPropertyInteger('VarProduction')),
|
||||
$this->getLastLogTimestamp($this->ReadPropertyInteger('VarFeedIn')),
|
||||
$this->getLastLogTimestamp($this->ReadPropertyInteger('VarGrid'))
|
||||
);
|
||||
}
|
||||
|
||||
$noDataHint = ($lastLogTs > 0) ? 'Letzter Zeitpunkt: ' . date('d.m.Y H:i', $lastLogTs) : '';
|
||||
|
||||
|
||||
// House = Prod - Feed + Grid
|
||||
@@ -109,13 +118,8 @@ class Energy_Pie extends IPSModule
|
||||
'Einspeisung' => (float)$feed,
|
||||
'Netz' => (float)$grid,
|
||||
'Hausverbrauch' => (float)$house
|
||||
],
|
||||
// kannst du später entfernen
|
||||
'debug' => [
|
||||
'prod' => $dbgProd,
|
||||
'feed' => $dbgFeed,
|
||||
'grid' => $dbgGrid
|
||||
]
|
||||
|
||||
];
|
||||
$this->UpdateVisualizationValue(json_encode($payload, JSON_THROW_ON_ERROR));
|
||||
}
|
||||
@@ -128,11 +132,13 @@ class Energy_Pie extends IPSModule
|
||||
$base = strtotime($dateYmd . ' 00:00:00') ?: strtotime(date('Y-m-d') . ' 00:00:00');
|
||||
switch ($range) {
|
||||
case 'day':
|
||||
return [$base, $base + 86400];
|
||||
$end = strtotime('+1 day', $base);
|
||||
return [$base, $end];
|
||||
case 'week':
|
||||
$dow = (int)date('N', $base); // 1=Mon..7=Sun
|
||||
$start = $base - (($dow - 1) * 86400);
|
||||
return [$start, $start + 7 * 86400];
|
||||
$start = strtotime('-' . ($dow - 1) . ' days', $base);
|
||||
$end = strtotime('+7 days', $start);
|
||||
return [$start, $end];
|
||||
case 'month':
|
||||
$start = strtotime(date('Y-m-01 00:00:00', $base));
|
||||
$end = strtotime(date('Y-m-01 00:00:00', strtotime('+1 month', $start)));
|
||||
@@ -144,7 +150,8 @@ class Energy_Pie extends IPSModule
|
||||
return [$start, $end];
|
||||
|
||||
default:
|
||||
return [$base, $base + 86400];
|
||||
$end = strtotime('+1 day', $base);
|
||||
return [$base, $end];
|
||||
}
|
||||
}
|
||||
public function GetVisualizationPopup(): string
|
||||
@@ -159,6 +166,7 @@ class Energy_Pie extends IPSModule
|
||||
'varId' => $varId,
|
||||
'archiveId' => 0,
|
||||
'count' => 0,
|
||||
'inRange' => 0,
|
||||
'first' => null,
|
||||
'last' => null,
|
||||
'vStart' => null,
|
||||
@@ -172,18 +180,15 @@ class Energy_Pie extends IPSModule
|
||||
if ($archiveID <= 0) {
|
||||
return 0.0;
|
||||
}
|
||||
$values = @AC_GetLoggedValues($archiveID, $varId, $tStart - 86400, $tEnd + 86400, 0);
|
||||
$values = @AC_GetLoggedValues($archiveID, $varId, max(0, $tStart - 86400), $tEnd, 0);
|
||||
if (empty($values)) {
|
||||
return 0.0;
|
||||
}
|
||||
//usort($values, static fn($a, $b) => (int)$a['TimeStamp'] <=> (int)$b['TimeStamp']);
|
||||
|
||||
$firstTs = (int)$values[0]['TimeStamp'];
|
||||
$lastTs = (int)$values[count($values) - 1]['TimeStamp'];
|
||||
if ($firstTs > $lastTs) {
|
||||
$values = array_reverse($values);
|
||||
}
|
||||
|
||||
$dbg['count'] = count($values);
|
||||
$dbg['first'] = (float)$values[0]['Value'];
|
||||
$dbg['last'] = (float)$values[count($values) - 1]['Value'];
|
||||
@@ -191,10 +196,16 @@ class Energy_Pie extends IPSModule
|
||||
$vEnd = null;
|
||||
foreach ($values as $v) {
|
||||
$ts = (int)$v['TimeStamp'];
|
||||
if ($ts >= $tStart && $ts < $tEnd) {
|
||||
$dbg['inRange']++;
|
||||
}
|
||||
if ($ts <= $tStart) $vStart = (float)$v['Value'];
|
||||
if ($ts <= $tEnd) $vEnd = (float)$v['Value'];
|
||||
if ($ts > $tEnd) break;
|
||||
}
|
||||
if ($dbg['inRange'] === 0) {
|
||||
return 0.0;
|
||||
}
|
||||
if ($vStart === null) $vStart = $dbg['first'];
|
||||
if ($vEnd === null) $vEnd = $dbg['last'];
|
||||
$dbg['vStart'] = $vStart;
|
||||
@@ -202,7 +213,6 @@ class Energy_Pie extends IPSModule
|
||||
$diff = $vEnd - $vStart;
|
||||
return ($diff < 0) ? 0.0 : (float)$diff;
|
||||
}
|
||||
|
||||
private function getLastLogTimestamp(int $varId): int
|
||||
{
|
||||
if ($varId <= 0 || !IPS_VariableExists($varId)) {
|
||||
@@ -239,10 +249,10 @@ class Energy_Pie extends IPSModule
|
||||
$base = strtotime(($sign === -1 ? '-7 day' : '+7 day'), $base);
|
||||
break;
|
||||
case 'month':
|
||||
$base = strtotime(($sign === -1 ? '-1 month' : '+1 month'), $base);
|
||||
$base = strtotime(($sign === -1 ? 'first day of previous month' : 'first day of next month'), $base);
|
||||
break;
|
||||
case 'year':
|
||||
$base = strtotime(($sign === -1 ? '-1 year' : '+1 year'), $base);
|
||||
$base = strtotime(($sign === -1 ? 'first day of january previous year' : 'first day of january next year'), $base);
|
||||
break;
|
||||
}
|
||||
$this->WriteAttributeString(self::ATTR_DATE, date('Y-m-d', $base));
|
||||
|
||||
Reference in New Issue
Block a user