no message
This commit is contained in:
+12
-2
@@ -35,8 +35,18 @@
|
|||||||
document.getElementById('barPV').style.width = data.consPV + '%';
|
document.getElementById('barPV').style.width = data.consPV + '%';
|
||||||
document.getElementById('barGrid').style.width = data.consGrid + '%';
|
document.getElementById('barGrid').style.width = data.consGrid + '%';
|
||||||
}
|
}
|
||||||
function handleMessage(msg) { Apply(msg); }
|
function handleMessage(msg) {
|
||||||
// Kein requestAction-Aufruf hier nötig
|
try {
|
||||||
|
var data = (typeof msg === 'string') ? JSON.parse(msg) : msg;
|
||||||
|
Apply(data);
|
||||||
|
} catch(e) {
|
||||||
|
console.error('PV_Visu handleMessage error:', e, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Bind to HTML-SDK
|
||||||
|
if (typeof registerMessageHandler === 'function') {
|
||||||
|
registerMessageHandler(handleMessage);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
+23
-29
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
|
||||||
class PV_Visu extends IPSModule
|
class PV_Visu extends IPSModule
|
||||||
{
|
{
|
||||||
public function Create()
|
public function Create()
|
||||||
@@ -16,30 +17,23 @@ class PV_Visu extends IPSModule
|
|||||||
$this->SetVisualizationType(3);
|
$this->SetVisualizationType(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ApplyChanges()
|
public function ApplyChanges(): void
|
||||||
{
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
$this->RequestAction("update", 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Liefert das HTML-Template und injiziert initiale Tagesdaten
|
* Liefert das HTML-Template und injiziert initiale Daten
|
||||||
*/
|
*/
|
||||||
public function GetVisualizationTile()
|
public function GetVisualizationTile(): string
|
||||||
{
|
{
|
||||||
// Tageswerte berechnen
|
|
||||||
$start = strtotime('today 00:00');
|
$start = strtotime('today 00:00');
|
||||||
$end = time();
|
$end = time();
|
||||||
|
|
||||||
$prodID = $this->ReadPropertyInteger('VarProduction');
|
$prod = $this->GetDailyTotal($this->ReadPropertyInteger('VarProduction'), $start, $end);
|
||||||
$consID = $this->ReadPropertyInteger('VarConsumption');
|
$cons = $this->GetDailyTotal($this->ReadPropertyInteger('VarConsumption'), $start, $end);
|
||||||
$feedID = $this->ReadPropertyInteger('VarFeedIn');
|
$feed = $this->GetDailyTotal($this->ReadPropertyInteger('VarFeedIn'), $start, $end);
|
||||||
$gridID = $this->ReadPropertyInteger('VarGrid');
|
$grid = $this->GetDailyTotal($this->ReadPropertyInteger('VarGrid'), $start, $end);
|
||||||
|
|
||||||
$prod = $this->GetDailyTotal($prodID, $start, $end);
|
|
||||||
$cons = $this->GetDailyTotal($consID, $start, $end);
|
|
||||||
$feed = $this->GetDailyTotal($feedID, $start, $end);
|
|
||||||
$grid = $this->GetDailyTotal($gridID, $start, $end);
|
|
||||||
|
|
||||||
// Prozent-Quoten
|
// Prozent-Quoten
|
||||||
$prodCons = $prod > 0 ? ($cons / $prod) * 100 : 0;
|
$prodCons = $prod > 0 ? ($cons / $prod) * 100 : 0;
|
||||||
@@ -47,7 +41,7 @@ class PV_Visu extends IPSModule
|
|||||||
$consPV = $cons > 0 ? min($prod, $cons) / $cons * 100 : 0;
|
$consPV = $cons > 0 ? min($prod, $cons) / $cons * 100 : 0;
|
||||||
$consGrid = $cons > 0 ? ($grid / $cons) * 100 : 0;
|
$consGrid = $cons > 0 ? ($grid / $cons) * 100 : 0;
|
||||||
|
|
||||||
$initialData = [
|
$data = [
|
||||||
'prodCons' => round($prodCons, 1),
|
'prodCons' => round($prodCons, 1),
|
||||||
'prodFeed' => round($prodFeed, 1),
|
'prodFeed' => round($prodFeed, 1),
|
||||||
'consPV' => round($consPV, 1),
|
'consPV' => round($consPV, 1),
|
||||||
@@ -60,24 +54,23 @@ class PV_Visu extends IPSModule
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
// Script zur Injektion der initialen Daten
|
// Daten als JSON-String übergeben
|
||||||
$message = '<script>handleMessage(' . json_encode($initialData) . ');</script>';
|
$json = json_encode($data);
|
||||||
|
$this->UpdateVisualizationValue($json);
|
||||||
|
|
||||||
// HTML-Template laden
|
// HTML-Template laden und zurückgeben
|
||||||
$htmlPath = __DIR__ . '/module.html';
|
$htmlPath = __DIR__ . '/module.html';
|
||||||
if (!file_exists($htmlPath)) {
|
if (!file_exists($htmlPath)) {
|
||||||
$this->LogMessage("module.html nicht gefunden in $htmlPath", KL_ERROR);
|
$this->LogMessage("module.html nicht gefunden in $htmlPath", KL_ERROR);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
$html = file_get_contents($htmlPath);
|
return file_get_contents($htmlPath);
|
||||||
|
|
||||||
return $html . $message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback vom HTML: sendet frische Daten
|
* Callback vom HTML: sendet frische Daten
|
||||||
*/
|
*/
|
||||||
public function RequestAction($Ident, $Value)
|
public function RequestAction($Ident, $Value): void
|
||||||
{
|
{
|
||||||
if ($Ident === 'update') {
|
if ($Ident === 'update') {
|
||||||
$this->UpdateData();
|
$this->UpdateData();
|
||||||
@@ -89,15 +82,15 @@ class PV_Visu extends IPSModule
|
|||||||
/**
|
/**
|
||||||
* Aktualisiert Daten und sendet an Tile
|
* Aktualisiert Daten und sendet an Tile
|
||||||
*/
|
*/
|
||||||
public function UpdateData()
|
public function UpdateData(): void
|
||||||
{
|
{
|
||||||
$start = strtotime('today 00:00');
|
$start = strtotime('today 00:00');
|
||||||
$end = time();
|
$end = time();
|
||||||
|
|
||||||
$prod = $this->GetDailyTotal($this->ReadPropertyInteger('VarProduction'), $start, $end);
|
$prod = $this->GetDailyTotal($this->ReadPropertyInteger('VarProduction'), $start, $end);
|
||||||
$cons = $this->GetDailyTotal($this->ReadPropertyInteger('VarConsumption'), $start, $end);
|
$cons = $this->GetDailyTotal($this->ReadPropertyInteger('VarConsumption'), $start, $end);
|
||||||
$feed = $this->GetDailyTotal($this->ReadPropertyInteger('VarFeedIn'), $start, $end);
|
$feed = $this->GetDailyTotal($this->ReadPropertyInteger('VarFeedIn'), $start, $end);
|
||||||
$grid = $this->GetDailyTotal($this->ReadPropertyInteger('VarGrid'), $start, $end);
|
$grid = $this->GetDailyTotal($this->ReadPropertyInteger('VarGrid'), $start, $end);
|
||||||
|
|
||||||
$prodCons = $prod > 0 ? ($cons / $prod) * 100 : 0;
|
$prodCons = $prod > 0 ? ($cons / $prod) * 100 : 0;
|
||||||
$prodFeed = $prod > 0 ? ($feed / $prod) * 100 : 0;
|
$prodFeed = $prod > 0 ? ($feed / $prod) * 100 : 0;
|
||||||
@@ -117,13 +110,14 @@ class PV_Visu extends IPSModule
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->UpdateVisualizationValue($data);
|
$json = json_encode($data);
|
||||||
|
$this->UpdateVisualizationValue($json);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holt Tages-Aggregat aus dem IPS-Archiv
|
* Holt Tages-Aggregat aus dem IPS-Archiv
|
||||||
*/
|
*/
|
||||||
private function GetDailyTotal(int $varID, int $start, int $end)
|
private function GetDailyTotal(int $varID, int $start, int $end): float
|
||||||
{
|
{
|
||||||
if ($varID <= 0) {
|
if ($varID <= 0) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
|||||||
Reference in New Issue
Block a user