Skip to content

Commit

Permalink
Update v3.2.2024022
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilkware committed Feb 22, 2024
1 parent df6ae1f commit 75d1c4e
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 105 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![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-6.4-blue.svg)](https://www.symcon.de/produkt/)
[![Version](https://img.shields.io/badge/Modul%20Version-3.1.20231127-orange.svg)](https://github.com/Wilkware/IPSymconTwinkly)
[![Version](https://img.shields.io/badge/Modul%20Version-3.2.20240222-orange.svg)](https://github.com/Wilkware/IPSymconTwinkly)
[![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/IPSymconTwinkly/workflows/Check%20Style/badge.svg)](https://github.com/Wilkware/IPSymconTwinkly/actions)

Expand Down Expand Up @@ -236,6 +236,13 @@ __Beispiel__: `TWICKLY_DeviceName(12345, 'Lichterkette');` Ausgabe "Der Name wur

### 8. Versionshistorie

v3.2.20240222

* _NEU_: Anpassungen für IPS 7.x (Konfigurator & TileVisu)
* _NEU_: Schaltervariable migriert auf Boolean
* _FIX_: Übersetzungen nachgezogen
* _FIX_: Interne Bibliotheken überarbeitet

v3.1.20231127

* _NEU_: Steuerung der Film(effekte) hinzugefügt
Expand Down
3 changes: 3 additions & 0 deletions TwinklyDevice/locale.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"translations": {
"de": {
"Twinkly Device": "Twinkly Gerät",
"Twinkly fairy lights": "Twinkly Lichterkette",
"Smart LED fairy lights": "Smart LED Lichterkette",
"\nTWINKLY – The smart LED light string\n ": "\nTWINKLY – Die intelligente LED-Lichterkette\n ",
"The module is used to integrate and control Twinkly devices (smart LED light chains) in IP-Symcon.": "Das Modul dient zur Einbindung und Steuerung von Twinkly Geräten (Smarte LED Lichterketten) in IP-Symcon.",
"Mode": "Modus",
Expand Down
6 changes: 3 additions & 3 deletions TwinklyDevice/module.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"id": "{A8ACEF24-02E6-A5A6-8409-64B16A8A3DC0}",
"name": "Twinkly Device",
"url": "https://wilkware.de/ip-symcon-module/twinkly",
"type": 3,
"vendor": "Ledworks",
"aliases": [
"Smart LED Lichterkette",
"Twinkly Lichterkette"
"Twinkly fairy lights",
"Smart LED fairy lights"
],
"url": "https://wilkware.de/ip-symcon-module/twinkly",
"parentRequirements": [],
"childRequirements": [],
"implemented": [],
Expand Down
12 changes: 6 additions & 6 deletions TwinklyDevice/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function Create()
$exists = @$this->GetIDForIdent('Movie');

// Profile anlegen
$this->RegisterProfileInteger('Twinkly.Switch', 'Light', '', '', 0, 0, 0, $this->assoSWITCH);
//$this->RegisterProfileInteger('Twinkly.Switch', 'Light', '', '', 0, 0, 0, $this->assoSWITCH);
$this->RegisterProfileInteger('Twinkly.Effect', 'Stars', '', '', 1, 5, 1);
$this->RegisterProfileInteger('Twinkly.Mode', 'Remote', '', '', 0, 0, 0, $this->assoMODE);
$this->RegisterProfileInteger('Twinkly.ModeEx', 'Remote', '', '', 0, 0, 0, $this->assoMODEEX);
Expand All @@ -101,7 +101,7 @@ public function Create()
}

// Variablen erzeugen
$this->RegisterVariableInteger('Switch', $this->Translate('Switch'), 'Twinkly.Switch', 0);
$this->RegisterVariableBoolean('Switch', $this->Translate('Switch'), '~Switch', 0);
$this->RegisterVariableInteger('Mode', $this->Translate('Mode'), 'Twinkly.Mode', 1);
$this->RegisterVariableInteger('Color', $this->Translate('Color'), '~HexColor', 2);
$this->RegisterVariableInteger('Effect', $this->Translate('Effect'), 'Twinkly.Effect', 3);
Expand Down Expand Up @@ -199,7 +199,7 @@ public function RequestAction($ident, $value)
break;
case 'Switch':
$this->SetSwitch($value);
$this->SetValueInteger($ident, $value);
$this->SetValueBoolean($ident, $value);
break;
case 'Mode':
$this->SetMode($value);
Expand Down Expand Up @@ -516,7 +516,7 @@ public function DeviceName(string $value)
*
* @param bool $value State value.
*/
private function SetSwitch(int $value)
private function SetSwitch(bool $value)
{
if ($this->CheckLogin() === false) {
$this->SendDebug(__FUNCTION__, 'Login error!');
Expand All @@ -528,7 +528,7 @@ private function SetSwitch(int $value)
$token = $this->ReadAttributeString('Token');
// Mode
$mode = 'off'; // Default
if ($value == 1) { // 1 == 'On'
if ($value) { // 1 == 'On' (true)
$mode = $this->assoMODEEX[$this->GetValue('Mode')][4];
}
$this->SendDebug(__FUNCTION__, 'Switch mode: ' . $mode, 0);
Expand All @@ -545,7 +545,7 @@ private function SetSwitch(int $value)
*/
private function SetMode(int $value)
{
if ($this->GetValue('Switch') == 0) { // 0 == 'Off'
if ($this->GetValue('Switch') == false) { // 0 == 'Off' (false)
return;
}
if ($this->CheckLogin() === false) {
Expand Down
3 changes: 2 additions & 1 deletion TwinklyDiscovery/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
{
"type": "SelectCategory",
"name": "TargetCategory",
"caption": "Target Category:"
"caption": "Target Category:",
"visible": false
}
],
"actions": [
Expand Down
2 changes: 1 addition & 1 deletion TwinklyDiscovery/module.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "{4C36BA50-BD40-FA02-B567-354E28F45615}",
"name": "Twinkly Discovery",
"url": "https://wilkware.de/ip-symcon-module/twinkly",
"type": 5,
"vendor": "Ledworks",
"aliases": [],
"url": "https://wilkware.de/ip-symcon-module/twinkly",
"parentRequirements": [],
"childRequirements": [],
"implemented": [],
Expand Down
8 changes: 7 additions & 1 deletion TwinklyDiscovery/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ public function GetConfigurationForm()
{
$form = json_decode(file_get_contents(__DIR__ . '/form.json'), true);
$devices = $this->DiscoverDevices();
// Version check
$version = (float) IPS_GetKernelVersion();
// Save location
$location = $this->GetPathOfCategory($this->ReadPropertyInteger('TargetCategory'));
// Enable or disable "TargetCategory" for 6.x
if ($version < 7) {
$form['elements'][2]['visible'] = true;
}
// Build configuration list values
if (!empty($devices)) {
foreach ($devices as $device) {
Expand All @@ -60,7 +66,7 @@ public function GetConfigurationForm()
[
'moduleID' => '{A8ACEF24-02E6-A5A6-8409-64B16A8A3DC0}',
'configuration' => ['Host' => $device['host']],
'location' => $location,
'location' => ($version < 7) ? $location : [],
],
],
];
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);
}
}
27 changes: 19 additions & 8 deletions libs/ProfileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,8 @@ protected function RegisterProfileFloat($name, $icon, $prefix, $suffix, $minvalu

IPS_SetVariableProfileIcon($name, $icon);
IPS_SetVariableProfileText($name, $prefix, $suffix);
IPS_SetVariableProfileDigits($name, $digits);

if (($asso !== null) && (count($asso) !== 0)) {
$minvalue = 0;
$maxvalue = 0;
}
IPS_SetVariableProfileValues($name, $minvalue, $maxvalue, $stepsize);
IPS_SetVariableProfileDigits($name, $digits);

if (($asso !== null) && (count($asso) !== 0)) {
foreach ($asso as $ass) {
Expand All @@ -130,16 +125,32 @@ protected function RegisterProfileFloat($name, $icon, $prefix, $suffix, $minvalu
* @param string $suffix Variable suffix.
* @param array $asso Associations of the values.
*/
protected function RegisterProfileString($name, $icon, $prefix, $suffix, $asso = null)
protected function RegisterProfileString($name, $icon, $prefix, $suffix, $asso)
{
$this->RegisterProfileType($name, VARIABLETYPE_STRING);

IPS_SetVariableProfileText($name, $prefix, $suffix);
IPS_SetVariableProfileIcon($name, $icon);
IPS_SetVariableProfileText($name, $prefix, $suffix);

if (($asso !== null) && (count($asso) !== 0)) {
foreach ($asso as $ass) {
IPS_SetVariableProfileAssociation($name, $ass[0], $this->Translate($ass[1]), $ass[2], $ass[3]);
}
}
}

/**
* Returns the used profile name of a variable
*
* @param int $id Variable ID
* @return string Empty, or name of the profile
*/
protected function GetVariableProfile($id)
{
$variableProfileName = IPS_GetVariable($id)['VariableCustomProfile'];
if ($variableProfileName == '') {
$variableProfileName = IPS_GetVariable($id)['VariableProfile'];
}
return $variableProfileName;
}
}
14 changes: 14 additions & 0 deletions libs/VariableHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ protected function SetValueInteger(string $ident, int $value)
}
}

/**
* Update a float value.
*
* @param string $ident Ident of the float variable
* @param float $value Value of the float variable
*/
protected function SetValueFloat(string $ident, float $value)
{
$id = @$this->GetIDForIdent($ident);
if ($id !== false) {
SetValueFloat($id, $value);
}
}

/**
* Sets the variable inactive.
*
Expand Down
Loading

0 comments on commit 75d1c4e

Please sign in to comment.