From 29c89e5f5eb11dda3138a7a88fabb475c4c7cbf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=A4fliger?= Date: Wed, 18 Jun 2025 11:38:42 +0200 Subject: [PATCH] no message --- PV_Visu/module.php | 56 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/PV_Visu/module.php b/PV_Visu/module.php index 152bfe1..4803d7a 100644 --- a/PV_Visu/module.php +++ b/PV_Visu/module.php @@ -12,26 +12,60 @@ class PV_Visu extends IPSModule $this->SetVisualizationType(3); } - public function ApplyChanges(): void + public function ApplyChanges() { parent::ApplyChanges(); } - public function GetVisualizationTile(int $InstanceID): string - { - $file = __DIR__ . '/module.html'; - if (!file_exists($file)) { - $this->LogMessage("module.html nicht gefunden in $file", KL_ERROR); - return ''; - } - return $this->Translate(file_get_contents($file)); +public function GetVisualizationTile() +{ + // 1) Aktuelle Tagesdaten berechnen (gleiche Logik wie in UpdateData) + $start = strtotime('today 00:00'); + $end = time(); + + $prod = $this->GetDailyTotal($this->ReadPropertyInteger('VarProduction'), $start, $end); + $cons = $this->GetDailyTotal($this->ReadPropertyInteger('VarConsumption'), $start, $end); + $feed = $this->GetDailyTotal($this->ReadPropertyInteger('VarFeedIn'), $start, $end); + $grid = $this->GetDailyTotal($this->ReadPropertyInteger('VarGrid'), $start, $end); + + $prodCons = $prod > 0 ? $cons / $prod * 100 : 0; + $prodFeed = $prod > 0 ? $feed / $prod * 100 : 0; + $consPV = $cons > 0 ? min($prod, $cons) / $cons * 100 : 0; + $consGrid = $cons > 0 ? $grid / $cons * 100 : 0; + + $initialData = [ + 'prodCons' => round($prodCons, 1), + 'prodFeed' => round($prodFeed, 1), + 'consPV' => round($consPV, 1), + 'consGrid' => round($consGrid, 1), + 'value' => [ + 'prod' => round($prod, 2), + 'cons' => round($cons, 2), + 'feed' => round($feed, 2), + 'grid' => round($grid, 2), + ], + ]; + + // 2) JS-Snippet zum Injizieren der initialen Daten + $message = ''; + + // 3) Modul-HTML laden + $html = file_get_contents(__DIR__ . '/module.html'); + if ($html === false) { + $this->LogMessage("module.html nicht gefunden", KL_ERROR); + return ''; } + // 4) HTML + initiales Daten-Script zurückliefern + return $html . $message; +} /** * Callback aus dem HTML: Daten neu berechnen und senden */ - public function RequestAction(string $Ident, $Value): void + public function RequestAction(string $Ident, $Value) { if ($Ident === 'update') { $this->UpdateData(); @@ -43,7 +77,7 @@ class PV_Visu extends IPSModule /** * Tägliche Summen holen, Quoten berechnen und ans Frontend senden */ - protected function UpdateData(): void + protected function UpdateData() { $start = strtotime('today 00:00'); $end = time();