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 02c8649 commit 10b9ed5
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 470 deletions.
4 changes: 2 additions & 2 deletions TwinklyDevice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Ermöglicht die Kommunikation mit den Smart LED-Leuchten _Twinkly_.
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 @@ -106,7 +106,7 @@ Twinkly.ModeEx | Integer | Extended LED-Betriebsmodus (0=Color, 1=Effekt
Twinkly.Effect | Integer | Vordefinierte Effekte (1..5)
Twinkly.Movie | Integer | Hinterlegte Filme (-1 für keine; >0 für hinterlegte Filme)

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

Die pro Twinkly Gerät erzeugten Variablen können direkt ins Webfront verlingt werden.

Expand Down
4 changes: 2 additions & 2 deletions TwinklyDiscovery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Ermöglicht die Gerätesuche für alle im Netzwerk befindlichen _Twinkly_ Gerät
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 @@ -63,7 +63,7 @@ Geräte | Liste zum Verwalten der entsprechenden Geräte-Instan

Es werden keine zusätzlichen Statusvariablen oder Profile benötigt.

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

Es ist keine weitere Steuerung oder gesonderte Darstellung integriert.

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
456 changes: 0 additions & 456 deletions libs/EventHelper.php

This file was deleted.

2 changes: 1 addition & 1 deletion libs/FormatHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
declare(strict_types=1);

/**
* Helper class for access satus variables.
* Helper class for formating and output json data.
*/
trait FormatHelper
{
Expand Down
2 changes: 1 addition & 1 deletion libs/TwinklyHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private function doLogin($ip)

$rand = random_bytes(32);
$base64 = base64_encode($rand);
$base64 = utf8_decode($base64);
#FIXME: $base64 = utf8_decode($base64); // not necessary

$login = ['challenge' => $base64];
$request = json_encode($login);
Expand Down
45 changes: 44 additions & 1 deletion libs/VariableHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,54 @@ protected function SetValueFloat(string $ident, float $value)
* @param string $ident Ident of the integer variable
* @param bool $value Enable or disable value the variable
*/
private function SetVariableDisabled(string $ident, bool $value)
protected function SetVariableDisabled(string $ident, bool $value)
{
$id = @$this->GetIDForIdent($ident);
if ($id !== false) {
IPS_SetDisabled($id, $value);
}
}

/**
* Check if the identifier is a valid variable identifier
*
* @param string $ident Variable identifier
* @param bool $exist may exist variable
* @return string (correct) variable identifier
*/
protected function GetVariableIdent(string $ident, bool $exist = false)
{
// Replace not allowed chars
$fixchar = ['/ä/', '/ö/', '/ü/', '/Ä/', '/Ö/', '/Ü/', '/ß/'];
$replace = ['ae', 'oe', 'ue', 'AE', 'OE', 'UE', 'ss'];
$ident = preg_replace($fixchar, $replace, $ident);

// Replace spaces with underscores
$ident = str_replace(' ', '_', $ident);

// If the passed identifier is empty, simply set it to underscore
if (empty($ident)) {
$ident = '_';
}

// Allow only allowed characters
$ident = preg_replace('/[^a-z0-9_]+/i', '', $ident);

// If the identifier starts with a number, prepend an underscore
//if (preg_match('/^[0-9]/', $ident)) {
// $ident = '_' . $ident;
//}

// If the identifier is already in use, append a number to make it unique
if ($exist) {
$counter = 1;
$originalIdent = $ident;
while (@$this->GetIDForIdent($ident) !== false) {
$ident = $originalIdent . '_' . $counter;
$counter++;
}
}

return $ident;
}
}
7 changes: 0 additions & 7 deletions libs/_traits.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,12 @@
define('IS_EBASE', 200); // Default errorcode
define('IS_NOTCREATED', IS_EBASE + 1); // Instance could not be created
}
if (!defined('vtBoolean')) {
define('vtBoolean', 0);
define('vtInteger', 1);
define('vtFloat', 2);
define('vtString', 3);
}

/**
* Include all helper trait classes.
*/
require_once __DIR__ . '/../libs/ColorHelper.php';
require_once __DIR__ . '/../libs/DebugHelper.php';
require_once __DIR__ . '/../libs/EventHelper.php';
require_once __DIR__ . '/../libs/FormatHelper.php';
require_once __DIR__ . '/../libs/ProfileHelper.php';
require_once __DIR__ . '/../libs/TwinklyHelper.php';
Expand Down

0 comments on commit 10b9ed5

Please sign in to comment.