Skip to content

Commit

Permalink
Merge pull request #14 from symcon/fixes/upgrade-style-to-v3
Browse files Browse the repository at this point in the history
Update style
  • Loading branch information
Sunnyka98 authored Nov 16, 2023
2 parents 6a15eed + 96974b7 commit d6c0292
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
- name: Checkout module
uses: actions/checkout@master
- name: Check style
uses: symcon/action-style@master
uses: symcon/action-style@v3
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.idea/
.phpunit.*
.php_cs.cache
.php_cs.cache
.php-cs-fixer.cache
2 changes: 1 addition & 1 deletion .style
Submodule .style updated 3 files
+42 −33 .php-cs-fixer.php
+22 −0 README.md
+85 −0 json-check.php
98 changes: 53 additions & 45 deletions USBMapper/form.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
{
"elements":
[
{
"type": "Label",
"label": "\nThis module should not be used as of IP-Symcon 6.0. Please use udev rules to link USB-Ports.\n\n"
},
{ "type": "Label", "label": "This module is only functional with Linux and Raspberry Pi" },
{
"type": "List",
"name": "Devices",
"caption": "Devices",
"rowCount": 5,
"add": true,
"delete": true,
"sort": {
"column": "ID",
"direction": "ascending"
},
"columns": [{
"label": "Serial Port",
"name": "ID",
"width": "60px",
"add": 0,
"edit": {
"type": "SelectModule",
"moduleID": "{6DC3D946-0D31-450F-A8C6-C42DB8D7D4F1}"
}
}, {
"label": "Name",
"name": "Name",
"width": "100",
"add": "Select device"
}, {
"label": "Set port",
"name": "PortID",
"width": "auto",
"add": "",
"edit": {
"type": "Select", "name": "PortName", "caption": "PortID",
"options": []
}
}],
"values": []
}
]
"elements": [
{
"type": "Label",
"label": "\nThis module should not be used as of IP-Symcon 6.0. Please use udev rules to link USB-Ports.\n\n"
},
{
"type": "Label",
"label": "This module is only functional with Linux and Raspberry Pi"
},
{
"type": "List",
"name": "Devices",
"caption": "Devices",
"rowCount": 5,
"add": true,
"delete": true,
"sort": {
"column": "ID",
"direction": "ascending"
},
"columns": [
{
"label": "Serial Port",
"name": "ID",
"width": "60px",
"add": 0,
"edit": {
"type": "SelectModule",
"moduleID": "{6DC3D946-0D31-450F-A8C6-C42DB8D7D4F1}"
}
},
{
"label": "Name",
"name": "Name",
"width": "100",
"add": "Select device"
},
{
"label": "Set port",
"name": "PortID",
"width": "auto",
"add": "",
"edit": {
"type": "Select",
"name": "PortName",
"caption": "PortID",
"options": []
}
}
],
"values": []
}
]
}
18 changes: 9 additions & 9 deletions USBMapper/locale.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"translations": {
"de": {
"Devices": "Geräte",
"Set port": "Gesetzter Port",
"This module is only functional with Linux and Raspberry Pi": "Dieses Modul funktioniert nur unter Linux und Raspberry Pi",
"Serial Port": "Serial Port",
"\nThis module should not be used as of IP-Symcon 6.0. Please use udev rules to link USB-Ports.\n\n": "\nDieses Modul sollte ab IP-Symcon 6.0 nicht mehr verwendet werden. Bitte verwenden Sie udev-Regeln zur Verknüpfung von USB-Ports.\n\n"
}
}
"translations": {
"de": {
"Devices": "Geräte",
"Set port": "Gesetzter Port",
"This module is only functional with Linux and Raspberry Pi": "Dieses Modul funktioniert nur unter Linux und Raspberry Pi",
"Serial Port": "Serial Port",
"\nThis module should not be used as of IP-Symcon 6.0. Please use udev rules to link USB-Ports.\n\n": "\nDieses Modul sollte ab IP-Symcon 6.0 nicht mehr verwendet werden. Bitte verwenden Sie udev-Regeln zur Verknüpfung von USB-Ports.\n\n"
}
}
}
3 changes: 1 addition & 2 deletions USBMapper/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"name": "USBMapper",
"type": 0,
"vendor": "",
"aliases":
[
"aliases": [
"USBMapper"
],
"parentRequirements": [],
Expand Down
88 changes: 44 additions & 44 deletions USBMapper/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,50 @@ public function FixPorts()
}
}

public function GetConfigurationForm()
{
$formdata = json_decode(file_get_contents(__DIR__ . '/form.json'));

$usbDevices = $this->GetUSBDevices();

$selectUSB = [];
foreach ($usbDevices as $usbDevice) {
$selectUSB[] = ['label' => '' . substr($usbDevice['product'], 0, 16) . '(now: ' . $usbDevice['device'] . ')', 'value' => $usbDevice['id']];
}

$formdata->elements[2]->columns[2]->edit->options = $selectUSB;

if ($this->ReadPropertyString('Devices') != '') {
//Annotate existing elements
$devices = json_decode($this->ReadPropertyString('Devices'));
foreach ($devices as $device) {
//We only need to add annotations. Remaining data is merged from persistance automatically.
//Order is determinted by the order of array elements
if (IPS_ObjectExists($device->ID) && $device->ID !== 0) {

// Check if the selected device is a serial port
$rowColor = '';
if (!IPS_GetInstance($device->ID)['ModuleInfo']['ModuleID'] == '{6DC3D946-0D31-450F-A8C6-C42DB8D7D4F1}') {
$rowColor = '#FFFF00';
}

$formdata->elements[2]->values[] = [
'Name' => IPS_GetName($device->ID),
'rowColor' => $rowColor,

];
} else {
$formdata->elements[2]->values[] = [
'Name' => 'Not found!',
'rowColor' => '#FF0000',
];
}
}
}

return json_encode($formdata);
}

private function GetUSBDevices()
{
if (!stristr(PHP_OS, 'linux')) {
Expand Down Expand Up @@ -121,48 +165,4 @@ private function GetUSBDevices()
}
return $result;
}

public function GetConfigurationForm()
{
$formdata = json_decode(file_get_contents(__DIR__ . '/form.json'));

$usbDevices = $this->GetUSBDevices();

$selectUSB = [];
foreach ($usbDevices as $usbDevice) {
$selectUSB[] = ['label' => '' . substr($usbDevice['product'], 0, 16) . '(now: ' . $usbDevice['device'] . ')', 'value' => $usbDevice['id']];
}

$formdata->elements[2]->columns[2]->edit->options = $selectUSB;

if ($this->ReadPropertyString('Devices') != '') {
//Annotate existing elements
$devices = json_decode($this->ReadPropertyString('Devices'));
foreach ($devices as $device) {
//We only need to add annotations. Remaining data is merged from persistance automatically.
//Order is determinted by the order of array elements
if (IPS_ObjectExists($device->ID) && $device->ID !== 0) {

// Check if the selected device is a serial port
$rowColor = '';
if (!IPS_GetInstance($device->ID)['ModuleInfo']['ModuleID'] == '{6DC3D946-0D31-450F-A8C6-C42DB8D7D4F1}') {
$rowColor = '#FFFF00';
}

$formdata->elements[2]->values[] = [
'Name' => IPS_GetName($device->ID),
'rowColor' => $rowColor,

];
} else {
$formdata->elements[2]->values[] = [
'Name' => 'Not found!',
'rowColor' => '#FF0000',
];
}
}
}

return json_encode($formdata);
}
}
22 changes: 11 additions & 11 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"id": "{CFA5976F-9F73-4140-B54F-FB7ABF1A7A1B}",
"author": "Symcon GmbH",
"name": "USBMapper",
"url": "https://www.symcon.de/",
"compatibility": {
"version": "5.5"
},
"version": "1.0",
"build": 0,
"date": 0
}
"id": "{CFA5976F-9F73-4140-B54F-FB7ABF1A7A1B}",
"author": "Symcon GmbH",
"name": "USBMapper",
"url": "https://www.symcon.de/",
"compatibility": {
"version": "5.5"
},
"version": "1.0",
"build": 0,
"date": 0
}

0 comments on commit d6c0292

Please sign in to comment.