Skip to content

Commit

Permalink
Update Lib & Doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilkware committed Sep 8, 2024
1 parent c1982d9 commit 686d758
Show file tree
Hide file tree
Showing 12 changed files with 525 additions and 263 deletions.
2 changes: 1 addition & 1 deletion .style
Submodule .style updated 4 files
+28 −36 .php-cs-fixer.php
+139 −0 .php-json-fixer.php
+0 −183 .php_cs
+29 −10 README.md
234 changes: 194 additions & 40 deletions Pollination/form.json

Large diffs are not rendered by default.

95 changes: 48 additions & 47 deletions Pollination/locale.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
{
"translations": {
"de": {
"\nPollination\n ": "\nPollenflug\n ",
"This module retrieves the pollen danger index from DWD and displays it textually or graphically.": "Dieses Modul ruft den Pollenflug-Gefahrenindex von DWD ab und stellt ihn textuell bzw. graphisch dar.",
"Local and temporal settings ...": "Örtliche und zeitliche Einstellungen ...",
"State:": "Bundesland:",
"Region:": "Region:",
"Number of days:": "Anzahl darzustellende Tage:",
"1 day": "1 Tag",
"2 days": "2 Tage",
"3 days": "3 Tage",
"Style sheets (CSS) ...": "Formatvorlagen (CSS) ...",
"Use 3D gradient for table header?" : "3D Farbverlauf für Tabellenkopf verwenden?",
"Table [table]:": "Tabelle [table]:",
"Table head [thead]:": "Tabllenkopf [thead]",
"Table cells [th,td]:": "Tabellenzellen [th,td]:",
"Last row [tr:last-child]:": "Letzte Zeile [tr:last-child]:",
"Alternate row [tr:nth-child(even)]:": "Alternierende Zeile [tr:nth-child(even)]:",
"First cell [td:first-child]:": "Erste Zelle [td:first-child]:",
"Middle cells [td:not(:first-child):not(:last-child)]:": "Mittlere Zellen [td:not(:first-child):not(:last-child)]:",
"Last cell [td:last-child]:": "Letzte Zelle [td:last-child]:",
"Weekday [div.day]:": "Wochentag [div.day]:",
"Day of month [div.num]:": "Tag des Monats [div.num]:",
"Name of month [div.mon]:": "Monatsname [div.mon]:",
"Advanced settings ...": "Erweiterte Einstellungen ...",
"Create variable for day note?": "Variable für Tageshinweis anlegen?",
"Create variable for tabular prediction?": "Variable für tabellarische Vorhersage anlegen?",
"Create variable for image link on all german pollen count calendar?": "Variable für Bildlink auf gesamtdeutschen Pollenflugkalendar anlegen?",
"Create variables for selecting the local and temporal settings (overrides module configuration)?": "Variablen für die Auswahl der lokalen und zeitlichen Einstellungen anlegen (überschreibt die Modulkonfiguration)?",
"The following selection box activates or deactivates the daily update:": "Die nachfolgende Auswahlbox aktiviert bzw. deaktiviert die tägliche Aktualisierung:",
"Activate daily update?": "Tägliche Aktualisierung aktivieren?",
"Hazard index ...": "Gefahrenindex ...",
"Update": "Aktualisieren",
"Last update": "Letzte Aktualisierung",
"Next update": "Nächste Aktualisierung",
"Daily Note": "Tageshinweis",
"Forecast": "Vorhersage",
"Annual calendar": "Jahreskalender",
"State": "Bundesland",
"Region": "Region",
"Days": "Tage",
"Error while reading the DWD pollen danger index!" : "Fehler beim Auslesen des DWD Pollenflug-Gefahrenindex!",
"Error reading the last update!": "Fehler beim Auslesen der letzten Aktualisierung!",
"Error reading the next update!": "Fehler beim Auslesen der nächsten Aktualisierung!",
"Source code, donation and licence ...": "Quellcode, Spende und Lizenz ...",
"The software is free of charge for non-commercial use, I would appreciate a donation if you like the module.": "Die Software ist für die nicht kommzerielle Nutzung kostenlos, über eine Spende bei Gefallen des Moduls würde ich mich sehr freuen."
"translations": {
"de": {
"Pollen Count": "Pollenflug",
"\nPollination\n ": "\nPollenflug\n ",
"This module retrieves the pollen danger index from DWD and displays it textually or graphically.": "Dieses Modul ruft den Pollenflug-Gefahrenindex von DWD ab und stellt ihn textuell bzw. graphisch dar.",
"Local and temporal settings ...": "Örtliche und zeitliche Einstellungen ...",
"State:": "Bundesland:",
"Region:": "Region:",
"Number of days:": "Anzahl darzustellende Tage:",
"1 day": "1 Tag",
"2 days": "2 Tage",
"3 days": "3 Tage",
"Style sheets (CSS) ...": "Formatvorlagen (CSS) ...",
"Use 3D gradient for table header?": "3D Farbverlauf für Tabellenkopf verwenden?",
"Table [table]:": "Tabelle [table]:",
"Table head [thead]:": "Tabllenkopf [thead]",
"Table cells [th,td]:": "Tabellenzellen [th,td]:",
"Last row [tr:last-child]:": "Letzte Zeile [tr:last-child]:",
"Alternate row [tr:nth-child(even)]:": "Alternierende Zeile [tr:nth-child(even)]:",
"First cell [td:first-child]:": "Erste Zelle [td:first-child]:",
"Middle cells [td:not(:first-child):not(:last-child)]:": "Mittlere Zellen [td:not(:first-child):not(:last-child)]:",
"Last cell [td:last-child]:": "Letzte Zelle [td:last-child]:",
"Weekday [div.day]:": "Wochentag [div.day]:",
"Day of month [div.num]:": "Tag des Monats [div.num]:",
"Name of month [div.mon]:": "Monatsname [div.mon]:",
"Advanced settings ...": "Erweiterte Einstellungen ...",
"Create variable for day note?": "Variable für Tageshinweis anlegen?",
"Create variable for tabular prediction?": "Variable für tabellarische Vorhersage anlegen?",
"Create variable for image link on all german pollen count calendar?": "Variable für Bildlink auf gesamtdeutschen Pollenflugkalendar anlegen?",
"Create variables for selecting the local and temporal settings (overrides module configuration)?": "Variablen für die Auswahl der lokalen und zeitlichen Einstellungen anlegen (überschreibt die Modulkonfiguration)?",
"The following selection box activates or deactivates the daily update:": "Die nachfolgende Auswahlbox aktiviert bzw. deaktiviert die tägliche Aktualisierung:",
"Activate daily update?": "Tägliche Aktualisierung aktivieren?",
"Hazard index ...": "Gefahrenindex ...",
"Update": "Aktualisieren",
"Last update": "Letzte Aktualisierung",
"Next update": "Nächste Aktualisierung",
"Daily Note": "Tageshinweis",
"Forecast": "Vorhersage",
"Annual calendar": "Jahreskalender",
"State": "Bundesland",
"Region": "Region",
"Days": "Tage",
"Error while reading the DWD pollen danger index!": "Fehler beim Auslesen des DWD Pollenflug-Gefahrenindex!",
"Error reading the last update!": "Fehler beim Auslesen der letzten Aktualisierung!",
"Error reading the next update!": "Fehler beim Auslesen der nächsten Aktualisierung!",
"Source code, donation and licence ...": "Quellcode, Spende und Lizenz ...",
"The software is free of charge for non-commercial use, I would appreciate a donation if you like the module.": "Die Software ist für die nicht kommerzielle Nutzung kostenlos, über eine Spende bei Gefallen des Moduls würde ich mich sehr freuen."
}
}
}
}
8 changes: 3 additions & 5 deletions Pollination/module.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"id": "{3CF9CC0D-8C00-9FFC-FE7D-82CC65C69BE5}",
"name": "Pollen Count",
"url": "https://wilkware.de/ip-symcon-module/pollenflug/",
"type": 3,
"vendor": "",
"aliases": [
"Pollenflug"
],
"aliases": [],
"parentRequirements": [],
"childRequirements": [],
"implemented": [],
"prefix": "POLLEN",
"url": "https://wilkware.de/ip-symcon-module/pollenflug/"
"prefix": "POLLEN"
}
24 changes: 13 additions & 11 deletions Pollination/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

require_once __DIR__ . '/../libs/_traits.php'; // Generell funktions

// CLASS PollenCount
/**
* CLASS PollenCount
*/
class PollenCount extends IPSModule
{
use DebugHelper;
Expand Down Expand Up @@ -90,15 +92,15 @@ public function Create()
foreach (self::STATES as $state) {
$states[] = [$state['value'], $state['caption'], '', 0x800080];
}
$this->RegisterProfile(vtInteger, 'POLLEN.States', 'Macro', '', '', 0, 0, 0, 0, $states);
$this->RegisterProfileInteger('POLLEN.States', 'Macro', '', '', 0, 0, 0, $states);
foreach (self::REGIONS as $state => $regions) {
$profil = [];
foreach ($regions as $region) {
$profil[] = [$region['value'], $region['caption'], '', -1];
}
$this->RegisterProfile(vtInteger, 'POLLEN.' . $state, 'Image', '', '', 0, 0, 0, 0, $profil);
$this->RegisterProfileInteger('POLLEN.' . $state, 'Image', '', '', 0, 0, 0, $profil);
}
$this->RegisterProfile(vtInteger, 'POLLEN.Days', 'Calendar', '', '', 1, 3, 1, 0);
$this->RegisterProfileInteger('POLLEN.Days', 'Calendar', '', '', 1, 3, 1);
// Register daily update timer
$this->RegisterTimer('UpdateTimer', 0, 'POLLEN_Update(' . $this->InstanceID . ');');
$this->SendDebug('Create', 'Init Properties', 0);
Expand Down Expand Up @@ -141,12 +143,12 @@ public function ApplyChanges()
// Variables
$this->RegisterVariableInteger('LastUpdate', $this->Translate('Last update'), '~UnixTimestamp', 0);
$this->RegisterVariableInteger('NextUpdate', $this->Translate('Next update'), '~UnixTimestamp', 1);
$this->MaintainVariable('Hint', $this->Translate('Tageshinweis'), vtString, '~TextBox', 2, $hint);
$this->MaintainVariable('Forecast', $this->Translate('Forecast'), vtString, '~HTMLBox', 2, $forecast);
$this->MaintainVariable('Link', $this->Translate('Annual calendar'), vtString, '~HTMLBox', 2, $link);
$this->MaintainVariable('State', $this->Translate('State'), vtInteger, 'POLLEN.States', 3, $select);
$this->MaintainVariable('Region', $this->Translate('Region'), vtInteger, 'POLLEN.10', 3, $select);
$this->MaintainVariable('Days', $this->Translate('Days'), vtInteger, 'POLLEN.Days', 3, $select);
$this->MaintainVariable('Hint', $this->Translate('Tageshinweis'), VARIABLETYPE_STRING, '~TextBox', 2, $hint);
$this->MaintainVariable('Forecast', $this->Translate('Forecast'), VARIABLETYPE_STRING, '~HTMLBox', 2, $forecast);
$this->MaintainVariable('Link', $this->Translate('Annual calendar'), VARIABLETYPE_STRING, '~HTMLBox', 2, $link);
$this->MaintainVariable('State', $this->Translate('State'), VARIABLETYPE_INTEGER, 'POLLEN.States', 3, $select);
$this->MaintainVariable('Region', $this->Translate('Region'), VARIABLETYPE_INTEGER, 'POLLEN.10', 3, $select);
$this->MaintainVariable('Days', $this->Translate('Days'), VARIABLETYPE_INTEGER, 'POLLEN.Days', 3, $select);
if ($select) {
if ($this->GetValue('State') == 0) {
$state = self::STATES[0]['value'];
Expand Down Expand Up @@ -197,7 +199,7 @@ public function RequestAction($ident, $value)
// select the always the first
$this->SetValueInteger('Region', self::REGIONS[$value][0]['value']);
// No break, because 'State' have also to set the value
// FIXME: No break. Add additional comment above this line if intentional!
// No break. Add additional comment above this line if intentional!
case 'Region':
// No break, because 'Region' have also to set the value
case 'Days':
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Pollenflug

[![Version](https://img.shields.io/badge/Symcon-PHP--Modul-red.svg)](https://www.symcon.de/service/dokumentation/entwicklerbereich/sdk-tools/sdk-php/)
[![Product](https://img.shields.io/badge/Symcon%20Version-5.2%20%3E-blue.svg)](https://www.symcon.de/produkt/)
[![Version](https://img.shields.io/badge/Modul%20Version-3.0.20221007-orange.svg)](https://github.com/Wilkware/IPSymconPollination)
[![License](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-green.svg)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
[![Actions](https://github.com/Wilkware/IPSymconPollination/workflows/Check%20Style/badge.svg)](https://github.com/Wilkware/IPSymconPollination/actions)
[![Version](https://img.shields.io/badge/Symcon-PHP--Modul-red.svg?style=flat-square)](https://www.symcon.de/service/dokumentation/entwicklerbereich/sdk-tools/sdk-php/)
[![Product](https://img.shields.io/badge/Symcon%20Version-6.4-blue.svg?style=flat-square)](https://www.symcon.de/produkt/)
[![Version](https://img.shields.io/badge/Modul%20Version-3.0.20221007-orange.svg?style=flat-square)](https://github.com/Wilkware/Pollination)
[![License](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-green.svg?style=flat-square)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
[![Actions](https://img.shields.io/github/actions/workflow/status/wilkware/Pollination/style.yml?branch=main&label=CheckStyle&style=flat-square)](https://github.com/Wilkware/Pollination/actions)

Das Modul nutzt den von Deutschen Wetterdienst (DWD) bereitgestellten Pollenflug-Gefahrenindex (opendata.dwd.de) zur graphischen Aufbereitung und
erzeugt über alle Meldungen einen kurzen Tageshinweis für die entsprechenden Gefahren.
Expand All @@ -16,7 +16,7 @@ erzeugt über alle Meldungen einen kurzen Tageshinweis für die entsprechenden G
3. [Installation](#user-content-3-installation)
4. [Einrichten der Instanzen in IP-Symcon](#user-content-4-einrichten-der-instanzen-in-ip-symcon)
5. [Statusvariablen und Profile](#user-content-5-statusvariablen-und-profile)
6. [WebFront](#user-content-6-webfront)
6. [Visualisierung](#user-content-6-visualisierung)
7. [PHP-Befehlsreferenz](#user-content-7-php-befehlsreferenz)
8. [Versionshistorie](#user-content-8-versionshistorie)

Expand Down Expand Up @@ -46,17 +46,17 @@ index | array | Belastung für die nächsten 3 Tage (siehe Leg

### 2. Voraussetzungen

* IP-Symcon ab Version 6.0
* IP-Symcon ab Version 6.4

### 3. Installation

* Über den Modul Store das Modul _Pollenflug_ installieren.
* Alternativ Über das Modul-Control folgende URL hinzufügen.
`https://github.com/Wilkware/IPSymconPollination` oder `git://github.com/Wilkware/IPSymconPollination.git`
`https://github.com/Wilkware/Pollination` oder `git://github.com/Wilkware/Pollination.git`

### 4. Einrichten der Instanzen in IP-Symcon

* Unter "Instanz hinzufügen" ist das 'Pollen Count'-Modul (Alias: _Pollenflug_) unter dem Hersteller '(Geräte)' aufgeführt.
* Unter "Instanz hinzufügen" ist das _Pollenflug_-Modul unter dem Hersteller '(Geräte)' aufgeführt.

__Konfigurationsseite__:

Expand Down Expand Up @@ -139,9 +139,9 @@ POLLEN.110 | Integer | Regionen (111,112,113)
POLLEN.120 | Integer | Regionen (121,122,123,124)
POLLEN.Days | Integer | 1, 2 oder 3 Tage

### 6. WebFront
### 6. Visualisierung

Man kann die Statusvariablen direkt im WF verlinken.
Man kann die Statusvariablen direkt in die Visualisierung verlinken.

### 7. PHP-Befehlsreferenz

Expand Down
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"id": "{0689F3AA-928D-5B86-3342-039A34D6BD19}",
"name": "Pollination",
"author": "Wilkware (@Pitti)",
"url": "https://wilkware.de",
"compatibility": {
"version": "6.0"
"version": "6.4"
},
"name": "Pollination",
"version": "3.0",
"build": 20221007,
"date": 1665136800
Expand Down
46 changes: 46 additions & 0 deletions libs/DebugHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,52 @@ protected function SendDebug($msg, $data, $format = 0)
}
}

/**
* DebugPrint
*
* @param mixed $arr Array to print.
* @return string Pretty formated array data.
*/
protected function DebugPrint($arr)
{
$retStr = '';
if (is_array($arr)) {
foreach ($arr as $key=>$val) {
if (is_array($val)) {
$retStr .= '[' . $key . '] => ' . $this->PrettyPrint($val);
}else {
$retStr .= '[' . $key . '] => ' . $val . ', ';
}
}
}
return $retStr;
}

/**
* Safe Print
*
* @param mixed $var Variable to log
*/
protected function SafePrint($var)
{
if (is_array($var)) {
// Arrays als JSON-String ausgeben
return json_encode($var);
} elseif (is_object($var)) {
// Objekte als JSON-String ausgeben
return json_encode($var);
} elseif (is_bool($var)) {
// Boolesche Werte als 'true' oder 'false' ausgeben
return $var ? 'true' : 'false';
} elseif (is_null($var)) {
// Null-Werte als 'null' ausgeben
return 'null';
} else {
// Andere Typen direkt ausgeben
return $var;
}
}

/**
* Wrapper for default modul log messages
*
Expand Down
28 changes: 28 additions & 0 deletions libs/EventHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,32 @@ protected function GetWeeklyScheduleInfo($id, $time = null, $checkonly = false)

return $data;
}

/**
* Versucht eine Semaphore zu setzen und wiederholt dies bei Misserfolg bis zu 100 mal.
*
* @param string $ident Ein String der den Lock bezeichnet.
* @return boolean TRUE bei Erfolg, FALSE bei Misserfolg.
*/
private function SemaphoreEnter($ident)
{
for ($i = 0; $i < 100; $i++) {
if (IPS_SemaphoreEnter(__CLASS__ . '.' . (string) $this->InstanceID . (string) $ident, 1)) {
return true;
} else {
IPS_Sleep(mt_rand(1, 5));
}
}
return false;
}

/**
* Löscht eine Semaphore.
*
* @param string $ident Ein String der den Lock bezeichnet.
*/
private function SemaphoreLeave($ident)
{
IPS_SemaphoreLeave(__CLASS__ . '.' . (string) $this->InstanceID . (string) $ident);
}
}
Loading

0 comments on commit 686d758

Please sign in to comment.