From a67d1a5189294f9259a9fb212aa658891a102b4c Mon Sep 17 00:00:00 2001 From: Sunnyka <71286632+Sunnyka98@users.noreply.github.com> Date: Thu, 16 Nov 2023 09:42:51 +0100 Subject: [PATCH] Update style --- .github/workflows/style.yml | 2 +- .gitignore | 3 +- .style | 2 +- TaupunktBerechnung/module.php | 266 +++++++++++++++++----------------- 4 files changed, 137 insertions(+), 136 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 714b5b5..3713f68 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -10,4 +10,4 @@ jobs: - name: Checkout module uses: actions/checkout@master - name: Check style - uses: symcon/action-style@master \ No newline at end of file + uses: symcon/action-style@v3 \ No newline at end of file diff --git a/.gitignore b/.gitignore index c013e4b..df90c89 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store .idea/ .phpunit.* -.php_cs.cache \ No newline at end of file +.php_cs.cache +.php-cs-fixer.cache \ No newline at end of file diff --git a/.style b/.style index c94eb97..ec73bf7 160000 --- a/.style +++ b/.style @@ -1 +1 @@ -Subproject commit c94eb976e0c268721c3cb37fb0e81ec948920b5f +Subproject commit ec73bf742e18b049ad5c90de09033987d3ce671e diff --git a/TaupunktBerechnung/module.php b/TaupunktBerechnung/module.php index 2b4bf99..ad49d17 100644 --- a/TaupunktBerechnung/module.php +++ b/TaupunktBerechnung/module.php @@ -1,170 +1,170 @@ RegisterPropertyInteger('Humidity', 0); - $this->RegisterPropertyInteger('RoomTemperature', 0); + $this->RegisterPropertyInteger('Humidity', 0); + $this->RegisterPropertyInteger('RoomTemperature', 0); - $this->RegisterVariableFloat('DewPoint', $this->Translate('Dew Point'), '~Temperature', 0); - $this->RegisterVariableFloat('MoldRisk', $this->Translate('Risk of Mold Temperature'), '~Temperature', 1); - $this->RegisterVariableBoolean('MoldAlert', $this->Translate('Alert Risk of Mold'), '~Alert', 2); - } + $this->RegisterVariableFloat('DewPoint', $this->Translate('Dew Point'), '~Temperature', 0); + $this->RegisterVariableFloat('MoldRisk', $this->Translate('Risk of Mold Temperature'), '~Temperature', 1); + $this->RegisterVariableBoolean('MoldAlert', $this->Translate('Alert Risk of Mold'), '~Alert', 2); + } - public function Destroy() - { - //Never delete this line! - parent::Destroy(); - } + public function Destroy() + { + //Never delete this line! + parent::Destroy(); + } - public function ApplyChanges() - { - //Never delete this line! - parent::ApplyChanges(); + public function ApplyChanges() + { + //Never delete this line! + parent::ApplyChanges(); - $humidityID = $this->ReadPropertyInteger('Humidity'); - $temperatureID = $this->ReadPropertyInteger('RoomTemperature'); + $humidityID = $this->ReadPropertyInteger('Humidity'); + $temperatureID = $this->ReadPropertyInteger('RoomTemperature'); - if (!IPS_VariableExists($humidityID) || !IPS_VariableExists($temperatureID)) { - $this->SetStatus(200); //One of the Variable is missing - return; - } else { - $this->SetStatus(102); //All right - } + if (!IPS_VariableExists($humidityID) || !IPS_VariableExists($temperatureID)) { + $this->SetStatus(200); //One of the Variable is missing + return; + } else { + $this->SetStatus(102); //All right + } - //Messages - //Unregister all messages - foreach ($this->GetMessageList() as $senderID => $messages) { - foreach ($messages as $message) { - $this->UnregisterMessage($senderID, $message); - } + //Messages + //Unregister all messages + foreach ($this->GetMessageList() as $senderID => $messages) { + foreach ($messages as $message) { + $this->UnregisterMessage($senderID, $message); } - //Register necessary messages - $this->RegisterMessage($humidityID, VM_UPDATE); - $this->RegisterMessage($temperatureID, VM_UPDATE); + } + //Register necessary messages + $this->RegisterMessage($humidityID, VM_UPDATE); + $this->RegisterMessage($temperatureID, VM_UPDATE); - //Initial calculation + //Initial calculation + $this->Calculate(); + } + + public function MessageSink($TimeStamp, $SenderID, $Message, $Data) + { + $this->SendDebug('Sender ' . $SenderID, 'Message ' . $Message, 0); + if ($Message === VM_UPDATE) { $this->Calculate(); } + } - public function MessageSink($TimeStamp, $SenderID, $Message, $Data) - { - $this->SendDebug('Sender ' . $SenderID, 'Message ' . $Message, 0); - if ($Message === VM_UPDATE) { - $this->Calculate(); - } - } + private function Calculate(): bool + { + $humidityID = $this->ReadPropertyInteger('Humidity'); + $temperatureID = $this->ReadPropertyInteger('RoomTemperature'); - private function Calculate(): bool - { - $humidityID = $this->ReadPropertyInteger('Humidity'); - $temperatureID = $this->ReadPropertyInteger('RoomTemperature'); + if (!IPS_VariableExists($humidityID) || !IPS_VariableExists($temperatureID)) { + return false; + } - if (!IPS_VariableExists($humidityID) || !IPS_VariableExists($temperatureID)) { - return false; - } + $humidity = GetValue($humidityID); + $temperature = GetValue($temperatureID); - $humidity = GetValue($humidityID); - $temperature = GetValue($temperatureID); + $this->SetValue('DewPoint', $this->CalculateDewPoint($humidity, $temperature)); + $this->SetValue('MoldRisk', $this->CalculateMoldRisk($humidity, $temperature)); - $this->SetValue('DewPoint', $this->CalculateDewPoint($humidity, $temperature)); - $this->SetValue('MoldRisk', $this->CalculateMoldRisk($humidity, $temperature)); + return true; + } - return true; + private function CalculateDewPoint(float $humidity, float $temperature): float + { + //Source https://www.wetterochs.de/wetter/feuchte.html + + /*Bezeichnungen: + r = relative Luftfeuchte + T = Temperatur in °C + TK = Temperatur in Kelvin (TK = T + 273.15) + TD = Taupunkttemperatur in °C + DD = Dampfdruck in hPa + SDD = Sättigungsdampfdruck in hPa + + Parameter: + a = 7.5, b = 237.3 für T >= 0 + a = 7.6, b = 240.7 für T < 0 über Wasser (Taupunkt) + a = 9.5, b = 265.5 für T < 0 über Eis (Frostpunkt) + + R* = 8314.3 J/(kmol*K) (universelle Gaskonstante) + mw = 18.016 kg/kmol (Molekulargewicht des Wasserdampfes) + AF = absolute Feuchte in g Wasserdampf pro m3 Luft + + Formeln: + SDD(T) = 6.1078 * 10^((a*T)/(b+T)) + DD(r,T) = r/100 * SDD(T) + r(T,TD) = 100 * SDD(TD) / SDD(T) + TD(r,T) = b*v/(a-v) mit v(r,T) = log10(DD(r,T)/6.1078) + AF(r,TK) = 10^5 * mw/R* * DD(r,T)/TK; AF(TD,TK) = 10^5 * mw/R* * SDD(TD)/TK + */ + + if ($temperature >= 0) { + $a = 7.5; + $b = 237.3; + } else { + $a = 7.6; + $b = 240.7; } - private function CalculateDewPoint(float $humidity, float $temperature): float + $SDD = function ($temperature) use ($a, $b) { - //Source https://www.wetterochs.de/wetter/feuchte.html - - /*Bezeichnungen: - r = relative Luftfeuchte - T = Temperatur in °C - TK = Temperatur in Kelvin (TK = T + 273.15) - TD = Taupunkttemperatur in °C - DD = Dampfdruck in hPa - SDD = Sättigungsdampfdruck in hPa - - Parameter: - a = 7.5, b = 237.3 für T >= 0 - a = 7.6, b = 240.7 für T < 0 über Wasser (Taupunkt) - a = 9.5, b = 265.5 für T < 0 über Eis (Frostpunkt) - - R* = 8314.3 J/(kmol*K) (universelle Gaskonstante) - mw = 18.016 kg/kmol (Molekulargewicht des Wasserdampfes) - AF = absolute Feuchte in g Wasserdampf pro m3 Luft - - Formeln: - SDD(T) = 6.1078 * 10^((a*T)/(b+T)) - DD(r,T) = r/100 * SDD(T) - r(T,TD) = 100 * SDD(TD) / SDD(T) - TD(r,T) = b*v/(a-v) mit v(r,T) = log10(DD(r,T)/6.1078) - AF(r,TK) = 10^5 * mw/R* * DD(r,T)/TK; AF(TD,TK) = 10^5 * mw/R* * SDD(TD)/TK - */ - - if ($temperature >= 0) { - $a = 7.5; - $b = 237.3; - } else { - $a = 7.6; - $b = 240.7; - } + $this->SendDebug('Sättitigungsdampfdruck', 6.1078 * pow(10, (($a * $temperature) / ($b + $temperature))) . ' hPa', 0); + return 6.1078 * pow(10, (($a * $temperature) / ($b + $temperature))); + }; - $SDD = function ($temperature) use ($a, $b) - { - $this->SendDebug('Sättitigungsdampfdruck', 6.1078 * pow(10, (($a * $temperature) / ($b + $temperature))) . ' hPa', 0); - return 6.1078 * pow(10, (($a * $temperature) / ($b + $temperature))); - }; + $DD = function ($humidity, $temperature) use ($SDD) + { + $this->SendDebug('Dampfdruck', $humidity / 100 * $SDD($temperature) . ' hPa', 0); + return $humidity / 100 * $SDD($temperature); + }; - $DD = function ($humidity, $temperature) use ($SDD) - { - $this->SendDebug('Dampfdruck', $humidity / 100 * $SDD($temperature) . ' hPa', 0); - return $humidity / 100 * $SDD($temperature); - }; + $v = function ($humidity, $temperature) use ($DD) + { + return log10($DD($humidity, $temperature) / 6.1078); + }; - $v = function ($humidity, $temperature) use ($DD) - { - return log10($DD($humidity, $temperature) / 6.1078); - }; + $dewPoint = $b * $v($humidity, $temperature) / ($a - $v($humidity, $temperature)); - $dewPoint = $b * $v($humidity, $temperature) / ($a - $v($humidity, $temperature)); + return $dewPoint; + } - return $dewPoint; - } - - private function CalculateMoldRisk(float $humidity, float $temperature): float - { - //DewPoint + ~3.3°C - //Source https://sicherheitsingenieur.nrw/rechner/taupunkt-berechnen-schimmelgefahr/ + private function CalculateMoldRisk(float $humidity, float $temperature): float + { + //DewPoint + ~3.3°C + //Source https://sicherheitsingenieur.nrw/rechner/taupunkt-berechnen-schimmelgefahr/ - $dewPoint = $this->CalculateDewPoint($humidity, $temperature); - $moldPoint = $dewPoint + 3.3; + $dewPoint = $this->CalculateDewPoint($humidity, $temperature); + $moldPoint = $dewPoint + 3.3; - $this->SetAlert($moldPoint, $temperature); + $this->SetAlert($moldPoint, $temperature); - return $moldPoint; - } + return $moldPoint; + } - private function SetAlert($moldPoint, $temperature) - { - //Set Alert true if it is false and moldpoint higher equal than temperature - //Set Alert false if it is true and temperature is higher than moldpoint +1°C + private function SetAlert($moldPoint, $temperature) + { + //Set Alert true if it is false and moldpoint higher equal than temperature + //Set Alert false if it is true and temperature is higher than moldpoint +1°C - $alert = $this->GetValue('MoldAlert'); + $alert = $this->GetValue('MoldAlert'); - $this->SendDebug('AlertValue', $alert, 0); - $this->SendDebug('Moldpoint', $moldPoint, 0); - $this->SendDebug('Temperature', $temperature, 0); + $this->SendDebug('AlertValue', $alert, 0); + $this->SendDebug('Moldpoint', $moldPoint, 0); + $this->SendDebug('Temperature', $temperature, 0); - if (!$alert && ($moldPoint >= $temperature)) { - $this->SetValue('MoldAlert', true); - } elseif ($alert && (($moldPoint + 1) < $temperature)) { - $this->SetValue('MoldAlert', false); - } + if (!$alert && ($moldPoint >= $temperature)) { + $this->SetValue('MoldAlert', true); + } elseif ($alert && (($moldPoint + 1) < $temperature)) { + $this->SetValue('MoldAlert', false); } - } \ No newline at end of file + } +} \ No newline at end of file