From edd5d0d083a3081bb8481fe1ceea31c1a00d5935 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Mon, 22 Jun 2020 22:26:53 +0200 Subject: [PATCH] Moved the smaller plugins to separate folders. --- Hal.iml | 2 + plugins/hal-mqtt/build.xml | 4 +- plugins/hal-netscan/build.xml | 25 ++++ .../hal/plugin/netscan/NetScanController.java | 0 .../se/hal/plugin/netscan/NetworkDevice.java | 0 .../src}/se/hal/plugin/netscan/plugin.json | 2 +- plugins/hal-nutups/build.xml | 25 ++++ .../hal/plugin/nutups/NutUpsController.java | 50 +++++++- .../se/hal/plugin/nutups/NutUpsDevice.java | 112 ++++++++++++++++++ .../src}/se/hal/plugin/nutups/plugin.json | 2 +- plugins/hal-raspberry/build.xml | 3 + plugins/hal-tellstick/build.xml | 4 +- plugins/hal-zigbee/build.xml | 4 +- plugins/hal-zwave/build.xml | 4 +- resource/web/plugin_config.tmpl | 2 +- resource/web/property_config.tmpl | 2 +- src/se/hal/page/PluginConfigWebPage.java | 2 +- src/se/hal/plugin/nutups/NutUpsDevice.java | 64 ---------- 18 files changed, 233 insertions(+), 74 deletions(-) create mode 100644 plugins/hal-netscan/build.xml rename {src => plugins/hal-netscan/src}/se/hal/plugin/netscan/NetScanController.java (100%) mode change 100755 => 100644 rename {src => plugins/hal-netscan/src}/se/hal/plugin/netscan/NetworkDevice.java (100%) mode change 100755 => 100644 rename {src => plugins/hal-netscan/src}/se/hal/plugin/netscan/plugin.json (86%) mode change 100755 => 100644 create mode 100644 plugins/hal-nutups/build.xml rename {src => plugins/hal-nutups/src}/se/hal/plugin/nutups/NutUpsController.java (53%) mode change 100755 => 100644 create mode 100644 plugins/hal-nutups/src/se/hal/plugin/nutups/NutUpsDevice.java rename {src => plugins/hal-nutups/src}/se/hal/plugin/nutups/plugin.json (89%) mode change 100755 => 100644 delete mode 100755 src/se/hal/plugin/nutups/NutUpsDevice.java diff --git a/Hal.iml b/Hal.iml index f6d22b8a..d611eaaf 100755 --- a/Hal.iml +++ b/Hal.iml @@ -14,8 +14,10 @@ + + diff --git a/plugins/hal-mqtt/build.xml b/plugins/hal-mqtt/build.xml index 8a3983b8..7f949b1f 100644 --- a/plugins/hal-mqtt/build.xml +++ b/plugins/hal-mqtt/build.xml @@ -3,6 +3,9 @@ + + + @@ -13,7 +16,6 @@ - diff --git a/plugins/hal-netscan/build.xml b/plugins/hal-netscan/build.xml new file mode 100644 index 00000000..66d51ba9 --- /dev/null +++ b/plugins/hal-netscan/build.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/se/hal/plugin/netscan/NetScanController.java b/plugins/hal-netscan/src/se/hal/plugin/netscan/NetScanController.java old mode 100755 new mode 100644 similarity index 100% rename from src/se/hal/plugin/netscan/NetScanController.java rename to plugins/hal-netscan/src/se/hal/plugin/netscan/NetScanController.java diff --git a/src/se/hal/plugin/netscan/NetworkDevice.java b/plugins/hal-netscan/src/se/hal/plugin/netscan/NetworkDevice.java old mode 100755 new mode 100644 similarity index 100% rename from src/se/hal/plugin/netscan/NetworkDevice.java rename to plugins/hal-netscan/src/se/hal/plugin/netscan/NetworkDevice.java diff --git a/src/se/hal/plugin/netscan/plugin.json b/plugins/hal-netscan/src/se/hal/plugin/netscan/plugin.json old mode 100755 new mode 100644 similarity index 86% rename from src/se/hal/plugin/netscan/plugin.json rename to plugins/hal-netscan/src/se/hal/plugin/netscan/plugin.json index 67e3db04..d20867a4 --- a/src/se/hal/plugin/netscan/plugin.json +++ b/plugins/hal-netscan/src/se/hal/plugin/netscan/plugin.json @@ -1,6 +1,6 @@ { "version": 1.0, - "name": "Network Scanner", + "name": "Hal-Network Scanner", "interfaces": [ {"se.hal.intf.HalAutoScannableController": "se.hal.plugin.netscan.NetScanController"}, {"se.hal.intf.HalEventConfig": "se.hal.plugin.netscan.NetworkDevice"} diff --git a/plugins/hal-nutups/build.xml b/plugins/hal-nutups/build.xml new file mode 100644 index 00000000..e59f8e95 --- /dev/null +++ b/plugins/hal-nutups/build.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/se/hal/plugin/nutups/NutUpsController.java b/plugins/hal-nutups/src/se/hal/plugin/nutups/NutUpsController.java old mode 100755 new mode 100644 similarity index 53% rename from src/se/hal/plugin/nutups/NutUpsController.java rename to plugins/hal-nutups/src/se/hal/plugin/nutups/NutUpsController.java index f84cd58c..4186e649 --- a/src/se/hal/plugin/nutups/NutUpsController.java +++ b/plugins/hal-nutups/src/se/hal/plugin/nutups/NutUpsController.java @@ -1,3 +1,51 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2020 Ziver Koc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/* + * The MIT License (MIT) + * + * Copyright (c) 2020 Ziver Koc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package se.hal.plugin.nutups; import se.hal.HalContext; @@ -19,7 +67,7 @@ public class NutUpsController implements HalSensorController, HalAutoScannableCo public static Logger logger = LogUtil.getLogger(); private static final int SYNC_INTERVAL = 60 * 1000; - private HashMap registeredDevices = new HashMap<>(); + private HashMap registeredDevices = new HashMap<>(); private NutUPSClient client; private ScheduledExecutorService executor; private HalSensorReportListener listener; diff --git a/plugins/hal-nutups/src/se/hal/plugin/nutups/NutUpsDevice.java b/plugins/hal-nutups/src/se/hal/plugin/nutups/NutUpsDevice.java new file mode 100644 index 00000000..f6136782 --- /dev/null +++ b/plugins/hal-nutups/src/se/hal/plugin/nutups/NutUpsDevice.java @@ -0,0 +1,112 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2020 Ziver Koc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/* + * The MIT License (MIT) + * + * Copyright (c) 2020 Ziver Koc + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package se.hal.plugin.nutups; + +import se.hal.intf.HalSensorConfig; +import se.hal.intf.HalSensorController; +import se.hal.intf.HalSensorData; +import se.hal.struct.devicedata.PowerConsumptionSensorData; +import zutil.osal.linux.app.NutUPSClient; +import zutil.ui.Configurator; + +public class NutUpsDevice implements HalSensorConfig{ + + @Configurator.Configurable("UPS id") + private String upsId; + + + public NutUpsDevice(){} + + protected NutUpsDevice(NutUPSClient.UPSDevice ups){ + this.upsId = ups.getId(); + } + + + protected HalSensorData read(NutUPSClient.UPSDevice ups){ + PowerConsumptionSensorData data = new PowerConsumptionSensorData(); + data.setTimestamp(System.currentTimeMillis()); + data.setData(ups.getPowerUsage() * 1/60.0); // convert watt min to watt hour + return data; + } + + + public String getUpsId(){ + return upsId; + } + + + @Override + public long getDataInterval(){ + return 60*1000; // 1 min + } + + @Override + public boolean equals(Object obj){ + if (obj instanceof NutUpsDevice) + return upsId != null && upsId.equals(((NutUpsDevice)obj).upsId); + return false; + } + + public String toString(){ + return "upsId: "+ upsId; + } + + @Override + public AggregationMethod getAggregationMethod() { + return AggregationMethod.SUM; + } + @Override + public Class getSensorControllerClass() { + return NutUpsController.class; + } + @Override + public Class getSensorDataClass() { + return PowerConsumptionSensorData.class; + } +} diff --git a/src/se/hal/plugin/nutups/plugin.json b/plugins/hal-nutups/src/se/hal/plugin/nutups/plugin.json old mode 100755 new mode 100644 similarity index 89% rename from src/se/hal/plugin/nutups/plugin.json rename to plugins/hal-nutups/src/se/hal/plugin/nutups/plugin.json index 7facf7d2..514e303e --- a/src/se/hal/plugin/nutups/plugin.json +++ b/plugins/hal-nutups/src/se/hal/plugin/nutups/plugin.json @@ -1,6 +1,6 @@ { "version": 1.0, - "name": "NutUps", + "name": "Hal-NutUps", "interfaces": [ {"se.hal.intf.HalAutoScannableController": "se.hal.plugin.nutups.NutUpsController"}, {"se.hal.intf.HalSensorConfig": "se.hal.plugin.nutups.NutUpsDevice"} diff --git a/plugins/hal-raspberry/build.xml b/plugins/hal-raspberry/build.xml index d66e754b..fb9a1cb1 100644 --- a/plugins/hal-raspberry/build.xml +++ b/plugins/hal-raspberry/build.xml @@ -3,6 +3,9 @@ + + + diff --git a/plugins/hal-tellstick/build.xml b/plugins/hal-tellstick/build.xml index 19608a6b..85f7666f 100644 --- a/plugins/hal-tellstick/build.xml +++ b/plugins/hal-tellstick/build.xml @@ -3,6 +3,9 @@ + + + @@ -13,7 +16,6 @@ - diff --git a/plugins/hal-zigbee/build.xml b/plugins/hal-zigbee/build.xml index 97281d47..6ddeb149 100755 --- a/plugins/hal-zigbee/build.xml +++ b/plugins/hal-zigbee/build.xml @@ -3,6 +3,9 @@ + + + @@ -13,7 +16,6 @@ - diff --git a/plugins/hal-zwave/build.xml b/plugins/hal-zwave/build.xml index 1876bb63..26b4921b 100644 --- a/plugins/hal-zwave/build.xml +++ b/plugins/hal-zwave/build.xml @@ -27,6 +27,9 @@ + + + @@ -37,7 +40,6 @@ - diff --git a/resource/web/plugin_config.tmpl b/resource/web/plugin_config.tmpl index 64d2fe74..a0d11cf1 100644 --- a/resource/web/plugin_config.tmpl +++ b/resource/web/plugin_config.tmpl @@ -2,7 +2,7 @@
-
Local Events
+
Active plugins
diff --git a/resource/web/property_config.tmpl b/resource/web/property_config.tmpl index 4ca54625..c7843954 100644 --- a/resource/web/property_config.tmpl +++ b/resource/web/property_config.tmpl @@ -2,7 +2,7 @@
-
Local Events
+
Registered properties
diff --git a/src/se/hal/page/PluginConfigWebPage.java b/src/se/hal/page/PluginConfigWebPage.java index 9c7ba76f..8cc01e10 100644 --- a/src/se/hal/page/PluginConfigWebPage.java +++ b/src/se/hal/page/PluginConfigWebPage.java @@ -17,7 +17,7 @@ public class PluginConfigWebPage extends HalWebPage { public PluginConfigWebPage(){ super("plugins"); - super.getRootNav().createSubNav("Settings").createSubNav(this.getId(), "Plugins").setWeight(100); + super.getRootNav().createSubNav("Settings").createSubNav(this.getId(), "Plugins").setWeight(500); } @Override diff --git a/src/se/hal/plugin/nutups/NutUpsDevice.java b/src/se/hal/plugin/nutups/NutUpsDevice.java deleted file mode 100755 index 4997310d..00000000 --- a/src/se/hal/plugin/nutups/NutUpsDevice.java +++ /dev/null @@ -1,64 +0,0 @@ -package se.hal.plugin.nutups; - -import se.hal.intf.HalSensorConfig; -import se.hal.intf.HalSensorController; -import se.hal.intf.HalSensorData; -import se.hal.struct.devicedata.PowerConsumptionSensorData; -import zutil.osal.linux.app.NutUPSClient; -import zutil.ui.Configurator; - -public class NutUpsDevice implements HalSensorConfig{ - - @Configurator.Configurable("UPS id") - private String upsId; - - - public NutUpsDevice(){} - - protected NutUpsDevice(NutUPSClient.UPSDevice ups){ - this.upsId = ups.getId(); - } - - - protected HalSensorData read(NutUPSClient.UPSDevice ups){ - PowerConsumptionSensorData data = new PowerConsumptionSensorData(); - data.setTimestamp(System.currentTimeMillis()); - data.setData(ups.getPowerUsage() * 1/60.0); // convert watt min to watt hour - return data; - } - - - public String getUpsId(){ - return upsId; - } - - - @Override - public long getDataInterval(){ - return 60*1000; // 1 min - } - - @Override - public boolean equals(Object obj){ - if (obj instanceof NutUpsDevice) - return upsId != null && upsId.equals(((NutUpsDevice)obj).upsId); - return false; - } - - public String toString(){ - return "upsId: "+ upsId; - } - - @Override - public AggregationMethod getAggregationMethod() { - return AggregationMethod.SUM; - } - @Override - public Class getSensorControllerClass() { - return NutUpsController.class; - } - @Override - public Class getSensorDataClass() { - return PowerConsumptionSensorData.class; - } -}