no message
This commit is contained in:
+45
-11
@@ -12,26 +12,60 @@ class PV_Visu extends IPSModule
|
|||||||
$this->SetVisualizationType(3);
|
$this->SetVisualizationType(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ApplyChanges(): void
|
public function ApplyChanges()
|
||||||
{
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function GetVisualizationTile(int $InstanceID): string
|
public function GetVisualizationTile()
|
||||||
{
|
{
|
||||||
$file = __DIR__ . '/module.html';
|
// 1) Aktuelle Tagesdaten berechnen (gleiche Logik wie in UpdateData)
|
||||||
if (!file_exists($file)) {
|
$start = strtotime('today 00:00');
|
||||||
$this->LogMessage("module.html nicht gefunden in $file", KL_ERROR);
|
$end = time();
|
||||||
return '';
|
|
||||||
}
|
$prod = $this->GetDailyTotal($this->ReadPropertyInteger('VarProduction'), $start, $end);
|
||||||
return $this->Translate(file_get_contents($file));
|
$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
|
* 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') {
|
if ($Ident === 'update') {
|
||||||
$this->UpdateData();
|
$this->UpdateData();
|
||||||
@@ -43,7 +77,7 @@ class PV_Visu extends IPSModule
|
|||||||
/**
|
/**
|
||||||
* Tägliche Summen holen, Quoten berechnen und ans Frontend senden
|
* Tägliche Summen holen, Quoten berechnen und ans Frontend senden
|
||||||
*/
|
*/
|
||||||
protected function UpdateData(): void
|
protected function UpdateData()
|
||||||
{
|
{
|
||||||
$start = strtotime('today 00:00');
|
$start = strtotime('today 00:00');
|
||||||
$end = time();
|
$end = time();
|
||||||
|
|||||||
Reference in New Issue
Block a user