Refactoring

This commit is contained in:
dh
2024-11-28 11:59:06 +01:00
parent 646033353f
commit 432c295a24
15 changed files with 1230 additions and 1153 deletions
-7
View File
@@ -1,7 +0,0 @@
{
"translations": {
"de": {
}
}
}
+86 -70
View File
@@ -1,8 +1,9 @@
<?php
class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
public function Create() {
class Boiler_2_Stufig_Mit_Fueler extends IPSModule
{
public function Create()
{
parent::Create();
// Prioritäten
@@ -16,7 +17,7 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
$this->RegisterVariableString("PowerSteps", "PowerSteps"); // PowerSteps-Variable registrieren
// Trägheit system
$this->RegisterPropertyInteger("IdleCounterMax", 2);
$this->RegisterPropertyInteger("IdleCounterMax", 2);
$this->RegisterVariableInteger("IdleCounter", "IdleCounter", "", 0);
$this->SetValue("IdleCounter", 0);
@@ -26,9 +27,9 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
$this->RegisterPropertyInteger("Boilertemperatur", 0);
// Boiler spezifische Variablen
$this->RegisterVariableInteger("Boilermintemp", "Boilermintemp", "", 45);
$this->RegisterVariableInteger("Boilermaxtemp", "Boilermaxtemp", "", 60);
$this->RegisterVariableInteger("Boilerlegiotemp", "Boilerlegiotemp", "", 65);
$this->RegisterVariableInteger("Boilermintemp","Boilermintemp","",45);
$this->RegisterVariableInteger("Boilermaxtemp","Boilermaxtemp","",60);
$this->RegisterVariableInteger("Boilerlegiotemp","Boilerlegiotemp","",65);
$this->RegisterVariableInteger("LegioCounter", "LegioCounter", "", 0);
// Schaltkontakte
@@ -39,12 +40,14 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
$this->SetValue("Idle", true);
}
public function ApplyChanges() {
public function ApplyChanges()
{
parent::ApplyChanges();
}
// Aktionen verarbeiten
public function RequestAction($Ident, $Value) {
public function RequestAction($Ident, $Value)
{
switch ($Ident) {
case "SetCurrentPower":
$this->SetCurrentPower($Value);
@@ -57,12 +60,15 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
}
// Methode zum Setzen des aktuellen Stromverbrauchs
public function SetCurrentPower(int $power) {
public function SetCurrentPower(int $power)
{
// Schalte Kontakt Teillast und Vollast entsprechend der Power-Einstellung
if ($power == $this->ReadPropertyInteger("BoilerLeistungVolllast")) {
SetValue($this->ReadPropertyInteger("Kontakt_Volllast"), true);
SetValue($this->ReadPropertyInteger("Kontakt_Teillast"), false);
} elseif ($power == $this->ReadPropertyInteger("BoilerLeistungTeillast")) {
} elseif (
$power == $this->ReadPropertyInteger("BoilerLeistungTeillast")
) {
SetValue($this->ReadPropertyInteger("Kontakt_Volllast"), false);
SetValue($this->ReadPropertyInteger("Kontakt_Teillast"), true);
} else {
@@ -74,7 +80,10 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
$lastPower = GetValue($this->GetIDForIdent("CurrentPower"));
if ($power != $lastPower) {
$this->SetValue("Idle", false);
$this->SetValue("IdleCounter", $this->ReadPropertyInteger("IdleCounterMax"));
$this->SetValue(
"IdleCounter",
$this->ReadPropertyInteger("IdleCounterMax")
);
}
// Setze die neue CurrentPower
@@ -84,10 +93,9 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
$this->ProcessIdleCounter();
}
// Methode zum Abrufen der aktuellen Daten
public function GetCurrentData(bool $Peak) {
public function GetCurrentData(bool $Peak)
{
$LegioCounter = $this->GetValue("LegioCounter");
$boilerTemp = GetValue($this->ReadPropertyInteger("Boilertemperatur"));
@@ -96,70 +104,74 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
$LegioTemp = $this->GetValue("Boilerlegiotemp");
$teilLeistung = $this->ReadPropertyInteger("BoilerLeistungTeillast");
$vollLeistung = $this->ReadPropertyInteger("BoilerLeistungVolllast");
$AktuelleVollast = GetValue($this->ReadPropertyInteger("Kontakt_Volllast"));
$AktuelleTeillast = GetValue($this->ReadPropertyInteger("Kontakt_Teillast"));
if($boilerTemp>$LegioTemp){
$LegioCounter = 0;
IPS_LogMessage("im1", $LegioCounter);
}else{
$LegioCounter = $LegioCounter + 1;
IPS_LogMessage("im2", $LegioCounter);
$AktuelleVollast = GetValue(
$this->ReadPropertyInteger("Kontakt_Volllast")
);
$AktuelleTeillast = GetValue(
$this->ReadPropertyInteger("Kontakt_Teillast")
);
if ($boilerTemp > $LegioTemp) {
$LegioCounter = 0;
} else {
$LegioCounter = $LegioCounter + 1;
}
if($LegioCounter > 69120){
$maxTemp = $LegioTemp;
IPS_LogMessage("im3", $LegioCounter);
if ($LegioCounter > 69120) {
$maxTemp = $LegioTemp;
}
if(($LegioCounter>120960) && ($this->ist_nachts())){
$minTemp = $LegioTemp;
IPS_LogMessage("im4", $LegioCounter);
if ($LegioCounter > 120960 && $this->ist_nachts()) {
$minTemp = $LegioTemp;
}
$this->SetValue("LegioCounter", $LegioCounter);
if ($Peak) {
if ($boilerTemp < $minTemp) {
$this->SetValue("PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]));
} elseif ($boilerTemp < ($minTemp + 5) && ($AktuelleVollast || $AktuelleTeillast)) {
$this->SetValue("PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]));
}
else {
$this->SetValue(
"PowerSteps",
json_encode([0, $teilLeistung, $vollLeistung])
);
} elseif (
$boilerTemp < $minTemp + 5 &&
($AktuelleVollast || $AktuelleTeillast)
) {
$this->SetValue(
"PowerSteps",
json_encode([0, $teilLeistung, $vollLeistung])
);
} else {
$this->SetValue("PowerSteps", json_encode([0]));
}
}
} else {
if ($boilerTemp < $minTemp) {
$this->SetValue("PowerSteps", json_encode([$vollLeistung]));
} elseif ($boilerTemp < ($minTemp + 5) && ($AktuelleVollast || $AktuelleTeillast)) {
} elseif (
$boilerTemp < $minTemp + 5 &&
($AktuelleVollast || $AktuelleTeillast)
) {
$this->SetValue("PowerSteps", json_encode([$vollLeistung]));
}
elseif ($boilerTemp < ($maxTemp-5)) {
$this->SetValue("PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]));
}
elseif ($boilerTemp < ($maxTemp) && ($AktuelleVollast || $AktuelleTeillast)) {
$this->SetValue("PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]));
}
else {
} elseif ($boilerTemp < $maxTemp - 5) {
$this->SetValue(
"PowerSteps",
json_encode([0, $teilLeistung, $vollLeistung])
);
} elseif (
$boilerTemp < $maxTemp &&
($AktuelleVollast || $AktuelleTeillast)
) {
$this->SetValue(
"PowerSteps",
json_encode([0, $teilLeistung, $vollLeistung])
);
} else {
$this->SetValue("PowerSteps", json_encode([0]));
}
}
}
}
private function ProcessIdleCounter() {
private function ProcessIdleCounter()
{
// IdleCounter auslesen und verarbeiten
$idleCounter = $this->GetValue("IdleCounter");
if ($idleCounter > 0) {
@@ -170,11 +182,15 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
}
}
private function CheckIdle($power) {
private function CheckIdle($power)
{
$lastpower = GetValue("CurrentPower");
if ($lastpower != GetValue("CurrentPower")) {
$this->SetValue("Idle", false);
$this->SetValue("IdleCounter", $this->ReadPropertyInteger("IdleCounterMax"));
$this->SetValue(
"IdleCounter",
$this->ReadPropertyInteger("IdleCounterMax")
);
}
// IdleCounter auslesen und verarbeiten
$idleCounter = $this->GetValue("IdleCounter");
@@ -186,14 +202,14 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
}
}
private function ist_nachts()
{
date_default_timezone_set("Europe/Berlin"); // Setze hier deine Zeitzone
$aktuelle_zeit = strtotime(date("H:i")); // Aktuelle Zeit in Stunden und Minuten umwandeln
$start_nacht = strtotime("22:00"); // Startzeit der Nacht (22 Uhr)
$ende_nacht = strtotime("07:00"); // Endzeit der Nacht (7 Uhr)
private function ist_nachts() {
date_default_timezone_set('Europe/Berlin'); // Setze hier deine Zeitzone
$aktuelle_zeit = strtotime(date('H:i')); // Aktuelle Zeit in Stunden und Minuten umwandeln
$start_nacht = strtotime('22:00'); // Startzeit der Nacht (22 Uhr)
$ende_nacht = strtotime('07:00'); // Endzeit der Nacht (7 Uhr)
if ($aktuelle_zeit >= $start_nacht || $aktuelle_zeit < $ende_nacht) {
return true;
} else {