From 88db2d3d6735e98580885c984aa024a4abf892f3 Mon Sep 17 00:00:00 2001 From: "J.H. Artworks" <98522442+jhartworks@users.noreply.github.com> Date: Fri, 5 Jan 2024 12:32:03 +0100 Subject: [PATCH] Add files via upload --- ModCreator/form.json | 19 ++++++++++ ModCreator/module.json | 14 +++++++ ModCreator/module.php | 77 +++++++++++++++++++++++++++++++++++++++ ProfileSetter/form.json | 19 ++++++++++ ProfileSetter/module.json | 14 +++++++ ProfileSetter/module.php | 64 ++++++++++++++++++++++++++++++++ Renamer/form.json | 15 ++++++++ Renamer/module.json | 14 +++++++ Renamer/module.php | 39 ++++++++++++++++++++ library.json | 13 +++++++ 10 files changed, 288 insertions(+) create mode 100644 ModCreator/form.json create mode 100644 ModCreator/module.json create mode 100644 ModCreator/module.php create mode 100644 ProfileSetter/form.json create mode 100644 ProfileSetter/module.json create mode 100644 ProfileSetter/module.php create mode 100644 Renamer/form.json create mode 100644 Renamer/module.json create mode 100644 Renamer/module.php create mode 100644 library.json diff --git a/ModCreator/form.json b/ModCreator/form.json new file mode 100644 index 0000000..94ec56a --- /dev/null +++ b/ModCreator/form.json @@ -0,0 +1,19 @@ +{ + "elements": + [ + { "type": "SelectCategory", "name": "PropertyCategoryID", "caption": "Target" }, + { "type": "SelectInstance", "name": "PropertyGatewayID", "caption": "Gateway" }, + { "type": "SelectMedia", "name": "PropertyMediaID", "caption": "CSV" }, + { "type": "NumberSpinner", "name": "PropertyObjectSortOffset", "caption": "Sort-Offset" } + + ], + "actions": + [ + + { "type": "Button", "label": "Create", "onClick": "VTMC_createModobjects($id);" } + ], + "status": + [ + + ] +} \ No newline at end of file diff --git a/ModCreator/module.json b/ModCreator/module.json new file mode 100644 index 0000000..e554868 --- /dev/null +++ b/ModCreator/module.json @@ -0,0 +1,14 @@ +{ + "id": "{C3286C5E-8AAB-15C8-6662-13CE28C0C85C}", + "name": "ModCreator", + "type": 3, + "vendor": "J.H. Artworks", + "aliases": + [ + ], + "url": "https://jh-artworks.com", + "parentRequirements": [], + "childRequirements": [], + "implemented": [], + "prefix": "VTMC" +} \ No newline at end of file diff --git a/ModCreator/module.php b/ModCreator/module.php new file mode 100644 index 0000000..f562e27 --- /dev/null +++ b/ModCreator/module.php @@ -0,0 +1,77 @@ +RegisterPropertyInteger("PropertyCategoryID",0); + $this->RegisterPropertyInteger("PropertyGatewayID",0); + $this->RegisterPropertyInteger("PropertyMediaID",0); + $this->RegisterPropertyInteger("PropertyObjectSortOffset",0); + + } + + // Überschreibt die intere IPS_ApplyChanges($id) Funktion + public function ApplyChanges() { + // Diese Zeile nicht löschen + parent::ApplyChanges(); + } + /** + * Die folgenden Funktionen stehen automatisch zur Verfügung, wenn das Modul über die "Module Control" eingefügt wurden. + * Die Funktionen werden, mit dem selbst eingerichteten Prefix, in PHP und JSON-RPC wiefolgt zur Verfügung gestellt: + * + * + */ + private function createModobject($socket, $catId, $pos, $objectName,$adressread,$fcread, $adresswrite, $fcwrite, $datatype,$factor,$byteorder) { + + + $newInstance = IPS_CreateInstance("{CB197E50-273D-4535-8C91-BB35273E3CA5}"); + IPS_DisconnectInstance($newInstance); + IPS_ConnectInstance($newInstance, $socket); + IPS_SetName($newInstance, $objectName); + + IPS_SetConfiguration($newInstance, '{"ByteOrder":'.$byteorder.',"DataType":'.$datatype.',"EmulateStatus":true,"Factor":'.$factor.',"Poller":1000,"ReadAddress":'.$adressread.',"ReadFunctionCode":'.$fcread.',"WriteAddress":'.$adresswrite.',"WriteFunctionCode":'.$fcwrite.'}'); + IPS_SetPosition($newInstance,$pos); + IPS_ApplyChanges($newInstance); + + IPS_SetParent($newInstance, $catId); + IPS_ApplyChanges($newInstance); + + + } + + public function createModobjects(){ + + $idCat = $this->ReadPropertyInteger("PropertyCategoryID"); + $idGw = $this->ReadPropertyInteger("PropertyGatewayID"); + $idMedia = $this->ReadPropertyInteger("PropertyMediaID"); + $sortoffset = $this->ReadPropertyInteger("PropertyObjectSortOffset"); + + $csv = base64_decode(IPS_GetMediaContent($idMedia)); + // Zeilen in ein Array aufteilen + $lines = explode(PHP_EOL, $csv); + + // Anzahl der Zeilen ermitteln + $totalLines = count($lines); + // echo $totalLines; + // Durch jede Zeile der CSV-Datei iterieren mit einem for loop + for ($row = 1; $row < $totalLines-1; $row++) { + // CSV-Zeile in ein Array von Daten aufteilen + $data = str_getcsv($lines[$row], ";", "\"", "\\"); + + // Überprüfen, ob es sich um die Kopfzeile oder eine Datenzeile handelt + if ($row > 0) { + // Hier kannst du die Modobject-Funktion mit den entsprechenden Indizes aus dem $data-Array aufrufen + //error_reporting(0); + $this->createModobject($idGw, $idCat, $row + $sortoffset, $data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6],$data[7]); + + // Beispiel-Ausgabe des ersten Elements in jeder Zeile + // print_r($data[7]); + } + } + + } +} +?> \ No newline at end of file diff --git a/ProfileSetter/form.json b/ProfileSetter/form.json new file mode 100644 index 0000000..d4eef3a --- /dev/null +++ b/ProfileSetter/form.json @@ -0,0 +1,19 @@ +{ + "elements": + [ + { "type": "SelectCategory", "name": "PropertyCategoryID", "caption": "Target" }, + { "type": "SelectProfile", "name": "PropertyProfileNameBool", "caption": "Profil - Bool" , "profileType": 0}, + { "type": "SelectProfile", "name": "PropertyProfileNameInt", "caption": "Profil - Integer" , "profileType": 1}, + { "type": "SelectProfile", "name": "PropertyProfileNameFloat", "caption": "Profil - Float" , "profileType": 2}, + { "type": "SelectProfile", "name": "PropertyProfileNameString", "caption": "Profil - String" , "profileType": 3} + ], + "actions": + [ + + { "type": "Button", "label": "Set selected Profiles", "onClick": "VTPS_setProfile($id);" } + ], + "status": + [ + + ] +} \ No newline at end of file diff --git a/ProfileSetter/module.json b/ProfileSetter/module.json new file mode 100644 index 0000000..82a8a4d --- /dev/null +++ b/ProfileSetter/module.json @@ -0,0 +1,14 @@ +{ + "id": "{74DEF544-0497-69C8-9802-00F641E279D9}", + "name": "ProfileSetter", + "type": 3, + "vendor": "J.H. Artworks", + "aliases": + [ + ], + "url": "https://jh-artworks.com", + "parentRequirements": [], + "childRequirements": [], + "implemented": [], + "prefix": "VTPS" +} \ No newline at end of file diff --git a/ProfileSetter/module.php b/ProfileSetter/module.php new file mode 100644 index 0000000..ffbccc7 --- /dev/null +++ b/ProfileSetter/module.php @@ -0,0 +1,64 @@ +RegisterPropertyInteger("PropertyCategoryID",0); + $this->RegisterPropertyString("PropertyProfileNameBool","~Switch"); + $this->RegisterPropertyString("PropertyProfileNameInt","~Intensity.100"); + $this->RegisterPropertyString("PropertyProfileNameFloat","~Temperature"); + $this->RegisterPropertyString("PropertyProfileNameString","~TextBox"); + + } + + // Überschreibt die intere IPS_ApplyChanges($id) Funktion + public function ApplyChanges() { + // Diese Zeile nicht löschen + parent::ApplyChanges(); + } + /** + * Die folgenden Funktionen stehen automatisch zur Verfügung, wenn das Modul über die "Module Control" eingefügt wurden. + * Die Funktionen werden, mit dem selbst eingerichteten Prefix, in PHP und JSON-RPC wiefolgt zur Verfügung gestellt: + * + * + */ + public function setProfile() { + + $idKat = $this->ReadPropertyInteger("PropertyCategoryID"); + $katChilds = IPS_GetChildrenIDs($idKat); + + foreach ($katChilds as $katChild) { + $chilid = IPS_GetChildrenIDs($katChild)[0]; + $parentname = IPS_GetName($katChild); + + $payload = GetValue($chilid); + // determine data type + if(is_string($payload)) { + $ips_var_type = 3; + $profile = $this->ReadPropertyString("PropertyProfileNameString"); + } else if(is_float($payload)) { + $ips_var_type = 2; + $profile = $this->ReadPropertyString("PropertyProfileNameFloat"); + } else if(is_int($payload)) { + $ips_var_type = 1; + $profile = $this->ReadPropertyString("PropertyProfileNameInt"); + } else if(is_bool($payload)) { + $ips_var_type = 0; + $profile = $this->ReadPropertyString("PropertyProfileNameBool"); + } else { // unsupported + return false; + } + + IPS_SetVariableCustomProfile($chilid, $profile); + + } + + } + + + +} +?> \ No newline at end of file diff --git a/Renamer/form.json b/Renamer/form.json new file mode 100644 index 0000000..af19041 --- /dev/null +++ b/Renamer/form.json @@ -0,0 +1,15 @@ +{ + "elements": + [ + { "type": "SelectCategory", "name": "PropertyCategoryID", "caption": "Target" } + ], + "actions": + [ + + { "type": "Button", "label": "Rename", "onClick": "VTRN_rename($id);" } + ], + "status": + [ + + ] +} \ No newline at end of file diff --git a/Renamer/module.json b/Renamer/module.json new file mode 100644 index 0000000..2fb575b --- /dev/null +++ b/Renamer/module.json @@ -0,0 +1,14 @@ +{ + "id": "{97873A1E-70E1-9AB9-0CA1-812C762E68FC}", + "name": "Renamer", + "type": 3, + "vendor": "J.H. Artworks", + "aliases": + [ + ], + "url": "https://jh-artworks.com", + "parentRequirements": [], + "childRequirements": [], + "implemented": [], + "prefix": "VTRN" +} \ No newline at end of file diff --git a/Renamer/module.php b/Renamer/module.php new file mode 100644 index 0000000..e72dfda --- /dev/null +++ b/Renamer/module.php @@ -0,0 +1,39 @@ +RegisterPropertyInteger("PropertyCategoryID",0); + } + + // Überschreibt die intere IPS_ApplyChanges($id) Funktion + public function ApplyChanges() { + // Diese Zeile nicht löschen + parent::ApplyChanges(); + } + /** + * Die folgenden Funktionen stehen automatisch zur Verfügung, wenn das Modul über die "Module Control" eingefügt wurden. + * Die Funktionen werden, mit dem selbst eingerichteten Prefix, in PHP und JSON-RPC wiefolgt zur Verfügung gestellt: + * + * + */ + public function rename() { + + $idKat = $this->ReadPropertyInteger("PropertyCategoryID"); + $katChilds = IPS_GetChildrenIDs($idKat); + + foreach ($katChilds as $katChild) { + $chilid = IPS_GetChildrenIDs($katChild)[0]; + $parentname = IPS_GetName($katChild); + $childname = $parentname; + IPS_SetName($chilid,$childname); + } + + } + + +} +?> \ No newline at end of file diff --git a/library.json b/library.json new file mode 100644 index 0000000..1cdce36 --- /dev/null +++ b/library.json @@ -0,0 +1,13 @@ +{ + "id": "{34065973-58B9-07E5-9FF2-09964F230304}", + "author": "J.H. Artworks", + "name": "VariableTools", + "url": "https://jh-artworks.com", + "compatibility": { + "version": "6.0", + "date": 1491343200 + }, + "version": "1.0", + "build": 1, + "date": 0 +} \ No newline at end of file