From fb671a9f5baca923823b5438b5d03088ab1bad34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=A4fliger?= Date: Mon, 14 Apr 2025 10:32:03 +0200 Subject: [PATCH] no message --- Verbraucher_extern/module.php | 44 +++++++++++++++-------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/Verbraucher_extern/module.php b/Verbraucher_extern/module.php index c6d7a24..abd6ace 100644 --- a/Verbraucher_extern/module.php +++ b/Verbraucher_extern/module.php @@ -67,33 +67,25 @@ class Verbraucher_extern extends IPSModule } - private function berechneKombinationen(array $verbraucherListe, float $power = null) + private function berechneKombinationen(array $verbraucherListe) { - $kombinationen = []; - $this->kombinationenRekursiv($verbraucherListe, [], $kombinationen, $power); - return $kombinationen; - } - - private function kombinationenRekursiv(array $verbraucherListe, array $aktuelleKombi, array &$kombinationen, float $power = null) - { - if (empty($verbraucherListe)) { - $summe = array_sum($aktuelleKombi); - if ($power === null || $summe <= $power) { - $kombinationen[] = $summe; + + $kombinationen = [0]; + + foreach ($verbraucherListe as $verbraucher) { + + if ($verbraucher['Read_Var'] == 1) { + $tempListe = $kombinationen; + foreach ($tempListe as &$wert) { + $wert += $verbraucher['P_Nenn']; + } + unset($wert); + $kombinationen = array_merge($kombinationen, $tempListe); + } } - return; - } - - $verbraucher = array_shift($verbraucherListe); - if ($this->GetValue($verbraucher['Read_Var']) == 1) { - $this->kombinationenRekursiv($verbraucherListe, array_merge($aktuelleKombi, [$verbraucher['P_Nenn']]), $kombinationen, $power); - } - $this->kombinationenRekursiv($verbraucherListe, $aktuelleKombi, $kombinationen, $power); + $kombinationen = array_unique(sort($kombinationen)); } - - - // Methode zum Setzen des aktuellen Stromverbrauchs public function SetAktuelle_Leistung(float $power) { $this->CheckIdle($power); @@ -106,15 +98,17 @@ class Verbraucher_extern extends IPSModule $pNenn = $verbraucher['P_Nenn']; $this->SetValue($writeVarID, in_array($pNenn, $kombinationen) ? 1 : 0); } - $this->SetValue("Leistung_Delta", $power - array_sum($kombinationen)); + $this->SetValue("Leistung_Delta", GetValue($this->ReadPropertyInteger("delta_power"))); } public function GetCurrentData(bool $Peak) { $this->SetValue("Is_Peak_Shaving", $Peak); + SetValue($this->ReadPropertyInteger("Is_Peak"), $Peak); + $verbraucherListe = json_decode($this->ReadPropertyString("Verbraucher_Liste"), true); $kombinationen = $this->berechneKombinationen($verbraucherListe); - $this->SetValue("PowerSteps", implode(", ", $kombinationen)); + $this->SetValue("PowerSteps", json_encode($kombinationen)); }