Refactoring
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
class WP_Steuerung extends IPSModule {
|
||||
|
||||
|
||||
public function Create() {
|
||||
class WP_Steuerung extends IPSModule
|
||||
{
|
||||
public function Create()
|
||||
{
|
||||
parent::Create();
|
||||
|
||||
// Prioritäten
|
||||
@@ -17,7 +17,7 @@ class WP_Steuerung extends IPSModule {
|
||||
$this->RegisterVariableString("PowerSteps", "PowerSteps"); // PowerSteps-Variable registrieren
|
||||
|
||||
// Trägheit
|
||||
$this->RegisterPropertyInteger("IdleCounterMax", 4);
|
||||
$this->RegisterPropertyInteger("IdleCounterMax", 4);
|
||||
$this->RegisterVariableInteger("IdleCounter", "IdleCounter", "", 0);
|
||||
$this->SetValue("IdleCounter", 0);
|
||||
|
||||
@@ -28,9 +28,6 @@ class WP_Steuerung extends IPSModule {
|
||||
$this->RegisterVariableInteger("WP_Laufzeit_Zahler", "WP_Laufzeit_Zahler", "", 20*12);
|
||||
$this->RegisterVariableBoolean("LetzterPeakwert", "LetzterPeakwert", "", false);
|
||||
$this->RegisterVariableBoolean("LetzterPeakwert_Aenderung", "LetzterPeakwert_Aenderung", "", false);
|
||||
|
||||
|
||||
|
||||
|
||||
$this->RegisterPropertyInteger("WP_Leistung", 6000);
|
||||
$this->RegisterPropertyInteger("Wolkenschwellwert", 60);
|
||||
@@ -47,240 +44,237 @@ class WP_Steuerung 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);
|
||||
break;
|
||||
case "GetCurrentData":
|
||||
return $this->GetCurrentData($Value);
|
||||
break;
|
||||
break;
|
||||
case "ResetPowerSteps":
|
||||
$this->ResetPowerSteps($Value);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid Ident");
|
||||
}
|
||||
}
|
||||
|
||||
// Methode zum Setzen des aktuellen Stromverbrauchs
|
||||
public function SetCurrentPower(float $power) {
|
||||
// Methode zum Setzen des aktuellen Stromverbrauchs
|
||||
public function SetCurrentPower(float $power)
|
||||
{
|
||||
$sperrzei_abs =
|
||||
((60 *
|
||||
60 *
|
||||
(GetValue($this->ReadPropertyInteger("Aussentemperatur")) +
|
||||
10)) /
|
||||
25) *
|
||||
6;
|
||||
|
||||
$sperrzei_abs = 60*60*(GetValue($this->ReadPropertyInteger("Aussentemperatur"))+10)/25*6;
|
||||
|
||||
if($sperrzei_abs>6*60*60){
|
||||
$sperrzei_abs = 6*60*60;
|
||||
|
||||
if ($sperrzei_abs > 6 * 60 * 60) {
|
||||
$sperrzei_abs = 6 * 60 * 60;
|
||||
}
|
||||
if($this->ReadPropertyInteger("Wolkenschwellwert")<GetValue($this->ReadPropertyInteger("Wolkenwert")) || $sperrzei_abs < 0 ){
|
||||
$sperrzei_abs = 0;
|
||||
|
||||
if (
|
||||
$this->ReadPropertyInteger("Wolkenschwellwert") <
|
||||
GetValue($this->ReadPropertyInteger("Wolkenwert")) ||
|
||||
$sperrzei_abs < 0
|
||||
) {
|
||||
$sperrzei_abs = 0;
|
||||
}
|
||||
$sperrzeit = GetValue($this->ReadPropertyInteger("Referenzzeit"))%86400 - $sperrzei_abs;
|
||||
$entsperrzeit = GetValue($this->ReadPropertyInteger("Referenzzeit"))%86400;
|
||||
$aktuellezeit = time()%86400;
|
||||
$sperrzeit = (GetValue($this->ReadPropertyInteger("Referenzzeit")) % 86400) - $sperrzei_abs;
|
||||
$entsperrzeit = GetValue($this->ReadPropertyInteger("Referenzzeit")) % 86400;
|
||||
$aktuellezeit = time() % 86400;
|
||||
|
||||
$this->CheckIdle($power);
|
||||
|
||||
$its_lock_time = $this->GetValue("Sperrzeit");
|
||||
if($aktuellezeit > $sperrzeit && $aktuellezeit < $entsperrzeit && $this->GetValue("WP_Laufzeit_Zahler")>240){
|
||||
$this->SetValue("Sperrzeit", true);
|
||||
|
||||
}
|
||||
elseif($this->GetValue("WP_Laufzeit_Zahler")>240){
|
||||
$this->SetValue("Sperrzeit", false);
|
||||
$its_lock_time = $this->GetValue("Sperrzeit");
|
||||
if (
|
||||
$aktuellezeit > $sperrzeit &&
|
||||
$aktuellezeit < $entsperrzeit &&
|
||||
$this->GetValue("WP_Laufzeit_Zahler") > 240
|
||||
) {
|
||||
$this->SetValue("Sperrzeit", true);
|
||||
} elseif ($this->GetValue("WP_Laufzeit_Zahler") > 240) {
|
||||
$this->SetValue("Sperrzeit", false);
|
||||
}
|
||||
|
||||
$newlocktime = $this->GetValue("Sperrzeit");
|
||||
$newlocktime = $this->GetValue("Sperrzeit");
|
||||
|
||||
|
||||
if($newlocktime == true && $its_lock_time==false && $this->GetValue("WP_Laufzeit_Zahler")>240){
|
||||
if (
|
||||
$newlocktime == true &&
|
||||
$its_lock_time == false &&
|
||||
$this->GetValue("WP_Laufzeit_Zahler") > 240
|
||||
) {
|
||||
$this->SetValue("WP_Laufzeit_Zahler", 0);
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), true);
|
||||
|
||||
}
|
||||
|
||||
elseif($newlocktime == false && $its_lock_time == true && $this->GetValue("WP_Laufzeit_Zahler")>240){
|
||||
} elseif (
|
||||
$newlocktime == false &&
|
||||
$its_lock_time == true &&
|
||||
$this->GetValue("WP_Laufzeit_Zahler") > 240
|
||||
) {
|
||||
$this->SetValue("WP_Laufzeit_Zahler", 0);
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
elseif($this->GetValue("CurrentPower")!=$power || ($this->GetValue("WP_Laufzeit_Zahler")>240 && ($this->GetValue("LetzterPeakwert") != $this->GetValue("LetzterPeakwert_Aenderung"))) ){
|
||||
} elseif (
|
||||
$this->GetValue("CurrentPower") != $power ||
|
||||
($this->GetValue("WP_Laufzeit_Zahler") > 240 &&
|
||||
$this->GetValue("LetzterPeakwert") !=
|
||||
$this->GetValue("LetzterPeakwert_Aenderung"))
|
||||
) {
|
||||
$this->SetValue("WP_Laufzeit_Zahler", 0);
|
||||
|
||||
$LastPeak = $this->GetValue("LetzterPeakwert");
|
||||
$this->SetValue("LetzterPeakwert_Aenderung", $LastPeak);
|
||||
$LastPeak = $this->GetValue("LetzterPeakwert");
|
||||
$this->SetValue("LetzterPeakwert_Aenderung", $LastPeak);
|
||||
$state = $this->GetValue("Zustand_WP");
|
||||
|
||||
if($state == 0){
|
||||
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
if ($state == 0) {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||
|
||||
}elseif($state == 1) // Normalbetrieb
|
||||
{
|
||||
if($LastPeak && $power == ($this->ReadPropertyInteger("WP_Leistung"))) {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue("CurrentPower", $this->ReadPropertyInteger("WP_Leistung"));
|
||||
|
||||
|
||||
} elseif($LastPeak && $power == 0){
|
||||
$this->SetValue("Zustand_WP", 2);
|
||||
$this->SetValue("CurrentPower", 0);
|
||||
|
||||
|
||||
}
|
||||
elseif($LastPeak == false && $power == ($this->ReadPropertyInteger("WP_Leistung"))){
|
||||
$this->SetValue("Zustand_WP", 3);
|
||||
$this->SetValue("CurrentPower", $this->ReadPropertyInteger("WP_Leistung"));
|
||||
|
||||
|
||||
}
|
||||
elseif($LastPeak == false && $power == 0){
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue("CurrentPower", 0);
|
||||
|
||||
}
|
||||
|
||||
}elseif($state == 2) // Sperre
|
||||
{
|
||||
if($LastPeak && $power == ($this->ReadPropertyInteger("WP_Leistung"))) {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue("CurrentPower", $this->ReadPropertyInteger("WP_Leistung"));
|
||||
|
||||
|
||||
} elseif($LastPeak && $power == 0){
|
||||
$this->SetValue("Zustand_WP", 2);
|
||||
$this->SetValue("CurrentPower", 0);
|
||||
|
||||
|
||||
}
|
||||
elseif($LastPeak == false && $power == ($this->ReadPropertyInteger("WP_Leistung"))){
|
||||
$this->SetValue("Zustand_WP", 3);
|
||||
$this->SetValue("CurrentPower", $this->ReadPropertyInteger("WP_Leistung"));
|
||||
|
||||
|
||||
}
|
||||
elseif($LastPeak == false && $power == 0){
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue("CurrentPower", 0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}elseif($state == 3) // Erhöht
|
||||
{
|
||||
|
||||
if($LastPeak && $power == ($this->ReadPropertyInteger("WP_Leistung"))) {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue("CurrentPower", $this->ReadPropertyInteger("WP_Leistung"));
|
||||
|
||||
} elseif($LastPeak && $power == 0){
|
||||
} elseif ($state == 1) {
|
||||
// Normalbetrieb
|
||||
if (
|
||||
$LastPeak &&
|
||||
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||
) {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue(
|
||||
"CurrentPower",
|
||||
$this->ReadPropertyInteger("WP_Leistung")
|
||||
);
|
||||
} elseif ($LastPeak && $power == 0) {
|
||||
$this->SetValue("Zustand_WP", 2);
|
||||
$this->SetValue("CurrentPower", 0);
|
||||
|
||||
|
||||
}
|
||||
elseif($LastPeak == false && $power == ($this->ReadPropertyInteger("WP_Leistung"))){
|
||||
$this->SetValue("Zustand_WP", 3);
|
||||
$this->SetValue("CurrentPower", $this->ReadPropertyInteger("WP_Leistung"));
|
||||
|
||||
|
||||
}
|
||||
elseif($LastPeak == false && $power == 0){
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
} elseif (
|
||||
$LastPeak == false &&
|
||||
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||
) {
|
||||
$this->SetValue("Zustand_WP", 3);
|
||||
$this->SetValue(
|
||||
"CurrentPower",
|
||||
$this->ReadPropertyInteger("WP_Leistung")
|
||||
);
|
||||
} elseif ($LastPeak == false && $power == 0) {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue("CurrentPower", 0);
|
||||
|
||||
}
|
||||
|
||||
} elseif ($state == 2) {
|
||||
// Sperre
|
||||
if (
|
||||
$LastPeak &&
|
||||
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||
) {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue(
|
||||
"CurrentPower",
|
||||
$this->ReadPropertyInteger("WP_Leistung")
|
||||
);
|
||||
} elseif ($LastPeak && $power == 0) {
|
||||
$this->SetValue("Zustand_WP", 2);
|
||||
$this->SetValue("CurrentPower", 0);
|
||||
} elseif (
|
||||
$LastPeak == false &&
|
||||
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||
) {
|
||||
$this->SetValue("Zustand_WP", 3);
|
||||
$this->SetValue(
|
||||
"CurrentPower",
|
||||
$this->ReadPropertyInteger("WP_Leistung")
|
||||
);
|
||||
} elseif ($LastPeak == false && $power == 0) {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue("CurrentPower", 0);
|
||||
}
|
||||
else{
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
} elseif ($state == 3) {
|
||||
// Erhöht
|
||||
if (
|
||||
$LastPeak &&
|
||||
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||
) {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue(
|
||||
"CurrentPower",
|
||||
$this->ReadPropertyInteger("WP_Leistung")
|
||||
);
|
||||
} elseif ($LastPeak && $power == 0) {
|
||||
$this->SetValue("Zustand_WP", 2);
|
||||
$this->SetValue("CurrentPower", 0);
|
||||
} elseif (
|
||||
$LastPeak == false &&
|
||||
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||
) {
|
||||
$this->SetValue("Zustand_WP", 3);
|
||||
$this->SetValue(
|
||||
"CurrentPower",
|
||||
$this->ReadPropertyInteger("WP_Leistung")
|
||||
);
|
||||
} elseif ($LastPeak == false && $power == 0) {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue("CurrentPower", 0);
|
||||
}
|
||||
} else {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
}
|
||||
|
||||
$newState = $this->GetValue("Zustand_WP");
|
||||
|
||||
if($newState == 0){
|
||||
|
||||
if ($newState == 0) {
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||
|
||||
}elseif($newState == 1){
|
||||
|
||||
} elseif ($newState == 1) {
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||
|
||||
}elseif($newState == 2){
|
||||
|
||||
} elseif ($newState == 2) {
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), true);
|
||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||
|
||||
}elseif($newState == 3){
|
||||
|
||||
} elseif ($newState == 3) {
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), true);
|
||||
|
||||
}else{
|
||||
|
||||
} else {
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
$newCount = $this->GetValue("WP_Laufzeit_Zahler");
|
||||
$this->SetValue("WP_Laufzeit_Zahler", ($newCount +1));
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
$newCount = $this->GetValue("WP_Laufzeit_Zahler");
|
||||
$this->SetValue("WP_Laufzeit_Zahler", $newCount + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Methode zum Abrufen der aktuellen Daten
|
||||
public function GetCurrentData(bool $Peak) {
|
||||
|
||||
public function GetCurrentData(bool $Peak)
|
||||
{
|
||||
// tagessperrzeit berechnen
|
||||
|
||||
|
||||
|
||||
$this->SetValue("LetzterPeakwert", $Peak);
|
||||
|
||||
$this->SetValue("LetzterPeakwert", $Peak);
|
||||
|
||||
if($this->GetValue("WP_Laufzeit_Zahler")<(20*12)){
|
||||
|
||||
$this->SetValue("PowerSteps", json_encode([$this->GetValue("CurrentPower")]));
|
||||
|
||||
}elseif($this->ReadPropertyBoolean("Schwellwert_Anwenden")==true && ($this->ReadPropertyInteger("Schwellwert")>GetValue($this->ReadPropertyInteger("WW_Temp"))) ){
|
||||
|
||||
|
||||
|
||||
$this->SetValue("PowerSteps", json_encode([$this->ReadPropertyInteger("WP_Leistung")]));
|
||||
}
|
||||
|
||||
else{
|
||||
|
||||
$this->SetValue("PowerSteps", json_encode([0, $this->ReadPropertyInteger("WP_Leistung")]));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function CheckIdle($power){
|
||||
$lastpower = GetValue($this->GetIDForIdent("CurrentPower"));
|
||||
if($lastpower != $power){
|
||||
public function CheckIdle($power)
|
||||
{
|
||||
$lastpower = GetValue($this->GetIDForIdent("CurrentPower"));
|
||||
if ($lastpower != $power) {
|
||||
$this->SetValue("Idle", false);
|
||||
$this->SetValue("IdleCounter", $this->ReadPropertyInteger("IdleCounterMax"));
|
||||
$this->SetValue(
|
||||
"IdleCounter",
|
||||
$this->ReadPropertyInteger("IdleCounterMax")
|
||||
);
|
||||
}
|
||||
// IdleCounter auslesen und verarbeiten
|
||||
$idleCounter = $this->GetValue("IdleCounter");
|
||||
@@ -292,4 +286,4 @@ class WP_Steuerung extends IPSModule {
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user