Auf Stand V2.001 gebracht, Sofarmodul ist jetzt integriert.
This commit is contained in:
@@ -68,10 +68,10 @@ class Verbraucher_extern extends IPSModule
|
||||
|
||||
|
||||
private function berechneKombinationen(array $verbraucherListe){
|
||||
$kombinationen = [];
|
||||
$kombinationen = [0];
|
||||
foreach ($verbraucherListe as $verbraucher) {
|
||||
|
||||
if (GetValue($verbraucher['Read_Var']) == 1) {
|
||||
if (GetValue($verbraucher['Read_Var']) == true) {
|
||||
$tempListe = [];
|
||||
if(empty($kombinationen)){
|
||||
$kombinationen[] = $verbraucher['P_Nenn'];
|
||||
@@ -87,6 +87,31 @@ class Verbraucher_extern extends IPSModule
|
||||
return array_values(array_unique($kombinationen));
|
||||
}
|
||||
|
||||
private function findCombinationRecursive($power, $values, $currentCombination, $startIndex, &$result) {
|
||||
if ($power == 0) {
|
||||
$result = $currentCombination;
|
||||
return true;
|
||||
}
|
||||
if ($power < 0) {
|
||||
return false;
|
||||
}
|
||||
for ($i = $startIndex; $i < count($values); $i++) {
|
||||
$currentCombination[] = $values[$i];
|
||||
if ($this->findCombinationRecursive($power - $values[$i], $values, $currentCombination, $i + 1, $result)) {
|
||||
return true;
|
||||
}
|
||||
array_pop($currentCombination);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private function findCombination($power, $values) {
|
||||
$result = [];
|
||||
$found = $this->findCombinationRecursive($power, $values, [], 0, $result);
|
||||
return $found ? $result : null;
|
||||
}
|
||||
|
||||
|
||||
private function find($target, $values, $current, &$result) {
|
||||
if ($target == 0) {
|
||||
@@ -106,19 +131,21 @@ class Verbraucher_extern extends IPSModule
|
||||
{
|
||||
$values = json_decode($this->GetValue("PowerSteps"));
|
||||
$result = [];
|
||||
|
||||
$this->find($this->GetValue("Power"), $values, [], $result);
|
||||
|
||||
$firstCombination = $this->findCombination($this->GetValue("Power"), json_decode($this->GetValue("PowerSteps")));
|
||||
|
||||
//$this->find($this->GetValue("Power"), $values, [], $result);
|
||||
|
||||
$verbraucherListe = json_decode($this->ReadPropertyString("Verbraucher_Liste"), true);
|
||||
|
||||
|
||||
$firstCombination = $result[0];
|
||||
//$firstCombination = $result[0];
|
||||
|
||||
foreach ($verbraucherListe as &$verbraucher) {
|
||||
foreach ($verbraucherListe as $verbraucher) {
|
||||
if (in_array($verbraucher['P_Nenn'], $firstCombination)) {
|
||||
SetValue($verbraucher['Write_Var'], 1);
|
||||
RequestAction($verbraucher['Write_Var'], true);
|
||||
} else {
|
||||
SetValue($verbraucher['Write_Var'], 0);
|
||||
RequestAction($verbraucher['Write_Var'], false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +168,7 @@ class Verbraucher_extern extends IPSModule
|
||||
public function GetCurrentData(bool $Peak)
|
||||
{
|
||||
$this->SetValue("Is_Peak_Shaving", $Peak);
|
||||
SetValue($this->ReadPropertyInteger("Is_Peak"), $Peak);
|
||||
RequestAction($this->ReadPropertyInteger("Is_Peak"), $Peak);
|
||||
|
||||
$verbraucherListe = json_decode($this->ReadPropertyString("Verbraucher_Liste"), true);
|
||||
$kombinationen = $this->berechneKombinationen($verbraucherListe);
|
||||
|
||||
Reference in New Issue
Block a user