Update for HomeGenie type handling

This commit is contained in:
BWS Systems
2019-06-26 14:05:36 -05:00
parent 0205633684
commit fcb31b8f76
7 changed files with 192 additions and 26 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>5.3.0RC5</version>
<version>5.3.0RC6</version>
<packaging>jar</packaging>
<name>HA Bridge</name>

View File

@@ -61,12 +61,12 @@ public class HomeGenieInstance {
if (hgModules != null && hgModules.length > 0) {
deviceList = new ArrayList<Module>();
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;

View File

@@ -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<Property> properties = null;
*/
* @SerializedName("Properties")
*
* @Expose private List<Property> 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<Property> getProperties() {
return properties;
}
public void setProperties(List<Property> properties) {
this.properties = properties;
}
*/
/*
* public List<Property> getProperties() { return properties; }
*
* public void setProperties(List<Property> 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;
}
}

View File

@@ -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;
}
}

View File

@@ -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<ModuleType> moduleTypes = null;
public List<ModuleType> getModuleTypes() {
return moduleTypes;
}
public void setModuleTypes(List<ModuleType> moduleTypes) {
this.moduleTypes = moduleTypes;
}
}

View File

@@ -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(

View File

@@ -716,6 +716,7 @@
<th>Port (opt)</th>
<th>Username (opt)</th>
<th>Password (opt)</th>
<th>Other Types (opt)</th>
<th>Use SSL</th>
<th>Manage</th>
</tr>
@@ -732,6 +733,11 @@
<td><input id="bridge-settings-next-homegenie-password" class="form-control"
type="password" ng-model="homegenie.password" placeholder="HomeGenie password">
</td>
<td>Currently: {{ convertModuleTypes($index) }}
<input id="bridge-settings-next-homegenie-othertypes" class="form-control" type="text"
ng-model="anExtensions" placeholder="type1, type2, type3">
<button class="btn btn-success" type="submit" ng-click="updateModuleTypes($index, anExtensions)">Update</button>
</td>
<td><input type="checkbox" ng-model="homegenie.secure" ng-true-value=true
ng-false-value=false></td>
<td><button class="btn btn-danger" type="submit"
@@ -750,10 +756,12 @@
<td><input id="bridge-settings-new-homegenie-password" class="form-control"
type="password" ng-model="newhomegeniepassword"
placeholder="HomeGenie password "></td>
<td><input id="bridge-settings-new-homegenie-othertypes" class="form-control" type="text"
ng-model="newhomegenieothertypes" placeholder="type1, type2, type3"></td>
<td><input type="checkbox" ng-model="newhomegeniesecure" ng-true-value=true
ng-false-value=false></td>
<td><button class="btn btn-success" type="submit"
ng-click="addHomeGenietoSettings(newhomegeniename, newhomegenieip, newhomegenieport, newshomegenieusername, newhomegeniepassword, newhomegeniewebhook, newhomegeniesecure)">Add</button>
ng-click="addHomeGenietoSettings(newhomegeniename, newhomegenieip, newhomegenieport, newshomegenieusername, newhomegeniepassword, newhomegeniewebhook, newhomegeniesecure, newhomegenieothertypes)">Add</button>
</td>
</tr>
</table>