diff --git a/pom.xml b/pom.xml index 45aa7b8..f2af946 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 5.3.0RC5 + 5.3.0RC6 jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/plugins/homegenie/HomeGenieInstance.java b/src/main/java/com/bwssystems/HABridge/plugins/homegenie/HomeGenieInstance.java index 9040cb0..b6c7d0d 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/homegenie/HomeGenieInstance.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/homegenie/HomeGenieInstance.java @@ -61,12 +61,12 @@ public class HomeGenieInstance { if (hgModules != null && hgModules.length > 0) { deviceList = new ArrayList(); for (int i = 0; i < hgModules.length; i++) { - if (hgModules[i].isSwitch() || hgModules[i].isDimmer()) + if (hgModules[i].isModuleValid(homegenieIP.getExtensions())) deviceList.add(hgModules[i]); } } } catch (Exception e) { - log.warn("Cannot get an devices for Homegenie {} Gson Parse Error.", homegenieIP.getName()); + log.warn("Cannot get devices for Homegenie {} Gson Parse Error.", homegenieIP.getName(), e); } } return deviceList; diff --git a/src/main/java/com/bwssystems/HABridge/plugins/homegenie/Module.java b/src/main/java/com/bwssystems/HABridge/plugins/homegenie/Module.java index 87f7a77..591719d 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/homegenie/Module.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/homegenie/Module.java @@ -1,11 +1,20 @@ package com.bwssystems.HABridge.plugins.homegenie; +import java.util.List; + // import java.util.List; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; + public class Module { + private static final Logger log = LoggerFactory.getLogger(HomeGenieInstance.class); @SerializedName("Name") @Expose @@ -23,10 +32,10 @@ public class Module { @Expose private String address; /* - @SerializedName("Properties") - @Expose - private List properties = null; - */ + * @SerializedName("Properties") + * + * @Expose private List properties = null; + */ @SerializedName("RoutingNode") @Expose private String routingNode; @@ -70,15 +79,13 @@ public class Module { public void setAddress(String address) { this.address = address; } -/* - public List getProperties() { - return properties; - } - public void setProperties(List properties) { - this.properties = properties; - } -*/ + /* + * public List getProperties() { return properties; } + * + * public void setProperties(List properties) { this.properties = + * properties; } + */ public String getRoutingNode() { return routingNode; } @@ -95,10 +102,48 @@ public class Module { return isDeviceType("Dimmer"); } + public boolean isLight() { + return isDeviceType("Light"); + } + private boolean isDeviceType(String theType) { - if(deviceType.equals(theType)) { + if (deviceType.equals(theType)) { return true; } return false; } + + public boolean isModuleValid(JsonObject theExtensions) { + ModuleTypes moduleTypes = null; + if (this.name == null || this.name.trim().isEmpty()) + return false; + + if (isSwitch()) + return true; + + if (isDimmer()) + return true; + + if (isLight()) + return true; + + if (theExtensions != null && theExtensions.isJsonObject() && theExtensions.get("moduleTypes").isJsonArray()) { + try { + moduleTypes = new Gson().fromJson(theExtensions, ModuleTypes.class); + } catch (Exception e) { + log.warn("Could not parse extensions for {} with {}", this.name, theExtensions); + return false; + } + + if (moduleTypes == null) + return false; + + for (ModuleType moduleType : moduleTypes.getModuleTypes()) { + if (isDeviceType(moduleType.getModuleType())) + return true; + } + } + + return false; + } } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/homegenie/ModuleType.java b/src/main/java/com/bwssystems/HABridge/plugins/homegenie/ModuleType.java new file mode 100644 index 0000000..0ebb050 --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/homegenie/ModuleType.java @@ -0,0 +1,20 @@ +package com.bwssystems.HABridge.plugins.homegenie; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class ModuleType { + + @SerializedName("moduleType") + @Expose + private String moduleType; + + public String getModuleType() { + return moduleType; + } + + public void setModuleType(String moduleType) { + this.moduleType = moduleType; + } + +} \ No newline at end of file diff --git a/src/main/java/com/bwssystems/HABridge/plugins/homegenie/ModuleTypes.java b/src/main/java/com/bwssystems/HABridge/plugins/homegenie/ModuleTypes.java new file mode 100644 index 0000000..04a318b --- /dev/null +++ b/src/main/java/com/bwssystems/HABridge/plugins/homegenie/ModuleTypes.java @@ -0,0 +1,21 @@ +package com.bwssystems.HABridge.plugins.homegenie; + +import java.util.List; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class ModuleTypes { + + @SerializedName("moduleTypes") + @Expose + private List moduleTypes = null; + + public List getModuleTypes() { + return moduleTypes; + } + + public void setModuleTypes(List moduleTypes) { + this.moduleTypes = moduleTypes; + } + +} \ No newline at end of file diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index 60a5722..79356f2 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -2071,12 +2071,39 @@ app.controller('SystemController', function ($scope, $location, bridgeService, n } }; - $scope.addHomeGenietoSettings = function (newhomegeniename, newhomegenieip, newhomegenieport, newhomegenieusername, newhomegeniepassword, newhomegeniewebhook, newhomegeniesecure) { + $scope.addHomeGenietoSettings = function (newhomegeniename, newhomegenieip, newhomegenieport, newhomegenieusername, newhomegeniepassword, newhomegeniewebhook, newhomegeniesecure, newhomegenieothertypes) { if ($scope.bridge.settings.homegenieaddress === undefined || $scope.bridge.settings.homegenieaddress === null) { $scope.bridge.settings.homegenieaddress = { devices: [] }; } + + var othertypes = []; + othertypes = newhomegenieothertypes.split(","); + var theModuleTypes = []; + var count = 0; + if (othertypes.length > 0) { + for (var i = 0; i < othertypes.length; i++) { + var aType = othertypes[i].trim(); + if (aType.length > 0) { + var moduleType = { + moduleType: aType + }; + theModuleTypes.push(moduleType); + count++; + } + } + } + var theExtension; + if (count == 0) { + theExtension = undefined; + } else { + theExtension = { + moduleTypes: theModuleTypes + } + + } + var newhomegenie = { name: newhomegeniename, ip: newhomegenieip, @@ -2084,16 +2111,61 @@ app.controller('SystemController', function ($scope, $location, bridgeService, n username: newhomegenieusername, password: newhomegeniepassword, secure: newhomegeniesecure, - webhook: newhomegeniewebhook + webhook: newhomegeniewebhook, + extensions: theExtension }; $scope.bridge.settings.homegenieaddress.devices.push(newhomegenie); $scope.newhomegeniename = null; $scope.newhomegenieip = null; - $scope.newhomegenieport = "8080"; + $scope.newhomegenieport = null; $scope.newhomegenieusername = null; $scope.newhomegeniepassword = null; $scope.newhomegeniewebhook = null; + $scope.newhomegenieextensions = null; }; + + $scope.updateModuleTypes = function (theIndex, homegenieExtensions) { + var othertypes = []; + if(homegenieExtensions != undefined) + othertypes = homegenieExtensions.split(","); + var theModuleTypes = []; + var count = 0; + if (othertypes.length > 0) { + for (var x = 0; x < othertypes.length; x++) { + var aType = othertypes[x].trim(); + if (aType.length > 0) { + var moduleType = { + moduleType: aType + }; + theModuleTypes.push(moduleType); + count++; + } + } + } + var theExtension; + if (count == 0) { + theExtension = undefined; + } else { + theExtension = { + moduleTypes: theModuleTypes + } + + } + $scope.bridge.settings.homegenieaddress.devices[theIndex].extensions = theExtension; + }; + + $scope.convertModuleTypes = function (theIndex) { + + var displayExtension = ""; + if ($scope.bridge.settings.homegenieaddress.devices[theIndex].extensions != undefined && $scope.bridge.settings.homegenieaddress.devices[theIndex].extensions.moduleTypes != undefined) { + for (var i = 0; i < $scope.bridge.settings.homegenieaddress.devices[theIndex].extensions.moduleTypes.length; i++) { + displayExtension = displayExtension + $scope.bridge.settings.homegenieaddress.devices[theIndex].extensions.moduleTypes[i].moduleType; + } + } + + return displayExtension; + }; + $scope.removeHomeGenietoSettings = function (homegeniename, homegenieip) { for (var i = $scope.bridge.settings.homegenieaddress.devices.length - 1; i >= 0; i--) { if ($scope.bridge.settings.homegenieaddress.devices[i].name === homegeniename && $scope.bridge.settings.homegenieaddress.devices[i].ip === homegenieip) { @@ -2409,7 +2481,7 @@ app.controller('ViewingController', function ($scope, $location, bridgeService, bridgeService.editDevice(device); $location.path('/editdevice'); }; - $scope.setStartupAction = function(device) { + $scope.setStartupAction = function (device) { $scope.bridge.device = device; ngDialog.open({ template: 'startupActionDialog', @@ -2426,7 +2498,7 @@ app.controller('ViewingController', function ($scope, $location, bridgeService, }; $scope.toggleLock = function (device) { - if(device.lockDeviceId) { + if (device.lockDeviceId) { device.lockDeviceId = false; } else { device.lockDeviceId = true; @@ -2567,9 +2639,9 @@ app.controller('StartupActionDialogCtrl', function ($scope, bridgeService, ngDia $scope.device = $scope.bridge.device; $scope.setDim = false; var components = []; - if($scope.device.startupActions != undefined) { + if ($scope.device.startupActions != undefined) { components = $scope.device.startupActions.split(":"); - if(components[1] != undefined && components[1].length > 0) + if (components[1] != undefined && components[1].length > 0) $scope.setDim = true; } else { components = "::".split(":"); @@ -2593,12 +2665,12 @@ app.controller('StartupActionDialogCtrl', function ($scope, bridgeService, ngDia console.log("Startup action set for device called: " + device.name); ngDialog.close('ngdialog1'); var theValue = 1; - if($scope.setDim) { + if ($scope.setDim) { theValue = $scope.theState + ":" + $scope.slider.value + ":" + $scope.rgbPicker.color; } else { theValue = $scope.theState + "::" + $scope.rgbPicker.color; } - if(theValue == "::") + if (theValue == "::") theValue = ""; device.startupActions = theValue; bridgeService.addDevice(device).then( diff --git a/src/main/resources/public/views/system.html b/src/main/resources/public/views/system.html index d3b341d..c55033f 100644 --- a/src/main/resources/public/views/system.html +++ b/src/main/resources/public/views/system.html @@ -716,6 +716,7 @@ Port (opt) Username (opt) Password (opt) + Other Types (opt) Use SSL Manage @@ -732,6 +733,11 @@ + Currently: {{ convertModuleTypes($index) }} + + + + ng-click="addHomeGenietoSettings(newhomegeniename, newhomegenieip, newhomegenieport, newshomegenieusername, newhomegeniepassword, newhomegeniewebhook, newhomegeniesecure, newhomegenieothertypes)">Add