no message

This commit is contained in:
2025-06-18 11:38:42 +02:00
parent f3119e7e30
commit 29c89e5f5e
+45 -11
View File
@@ -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 = '<script>'
. 'handleMessage(' . json_encode($initialData) . ');'
. '</script>';
// 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();