Compare commits

...

1 Commits

Author SHA1 Message Date
BWS Systems
fcb31b8f76 Update for HomeGenie type handling 2019-06-26 14:05:36 -05:00
7 changed files with 192 additions and 26 deletions

View File

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

View File

@@ -61,12 +61,12 @@ public class HomeGenieInstance {
if (hgModules != null && hgModules.length > 0) { if (hgModules != null && hgModules.length > 0) {
deviceList = new ArrayList<Module>(); deviceList = new ArrayList<Module>();
for (int i = 0; i < hgModules.length; i++) { 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]); deviceList.add(hgModules[i]);
} }
} }
} catch (Exception e) { } 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; return deviceList;

View File

@@ -1,11 +1,20 @@
package com.bwssystems.HABridge.plugins.homegenie; package com.bwssystems.HABridge.plugins.homegenie;
import java.util.List;
// import java.util.List; // import java.util.List;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; 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 { public class Module {
private static final Logger log = LoggerFactory.getLogger(HomeGenieInstance.class);
@SerializedName("Name") @SerializedName("Name")
@Expose @Expose
@@ -23,9 +32,9 @@ public class Module {
@Expose @Expose
private String address; private String address;
/* /*
@SerializedName("Properties") * @SerializedName("Properties")
@Expose *
private List<Property> properties = null; * @Expose private List<Property> properties = null;
*/ */
@SerializedName("RoutingNode") @SerializedName("RoutingNode")
@Expose @Expose
@@ -70,15 +79,13 @@ public class Module {
public void setAddress(String address) { public void setAddress(String address) {
this.address = 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() { public String getRoutingNode() {
return routingNode; return routingNode;
} }
@@ -95,10 +102,48 @@ public class Module {
return isDeviceType("Dimmer"); return isDeviceType("Dimmer");
} }
public boolean isLight() {
return isDeviceType("Light");
}
private boolean isDeviceType(String theType) { private boolean isDeviceType(String theType) {
if(deviceType.equals(theType)) { if (deviceType.equals(theType)) {
return true; return true;
} }
return false; 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) { if ($scope.bridge.settings.homegenieaddress === undefined || $scope.bridge.settings.homegenieaddress === null) {
$scope.bridge.settings.homegenieaddress = { $scope.bridge.settings.homegenieaddress = {
devices: [] 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 = { var newhomegenie = {
name: newhomegeniename, name: newhomegeniename,
ip: newhomegenieip, ip: newhomegenieip,
@@ -2084,16 +2111,61 @@ app.controller('SystemController', function ($scope, $location, bridgeService, n
username: newhomegenieusername, username: newhomegenieusername,
password: newhomegeniepassword, password: newhomegeniepassword,
secure: newhomegeniesecure, secure: newhomegeniesecure,
webhook: newhomegeniewebhook webhook: newhomegeniewebhook,
extensions: theExtension
}; };
$scope.bridge.settings.homegenieaddress.devices.push(newhomegenie); $scope.bridge.settings.homegenieaddress.devices.push(newhomegenie);
$scope.newhomegeniename = null; $scope.newhomegeniename = null;
$scope.newhomegenieip = null; $scope.newhomegenieip = null;
$scope.newhomegenieport = "8080"; $scope.newhomegenieport = null;
$scope.newhomegenieusername = null; $scope.newhomegenieusername = null;
$scope.newhomegeniepassword = null; $scope.newhomegeniepassword = null;
$scope.newhomegeniewebhook = 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) { $scope.removeHomeGenietoSettings = function (homegeniename, homegenieip) {
for (var i = $scope.bridge.settings.homegenieaddress.devices.length - 1; i >= 0; i--) { 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) { 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); bridgeService.editDevice(device);
$location.path('/editdevice'); $location.path('/editdevice');
}; };
$scope.setStartupAction = function(device) { $scope.setStartupAction = function (device) {
$scope.bridge.device = device; $scope.bridge.device = device;
ngDialog.open({ ngDialog.open({
template: 'startupActionDialog', template: 'startupActionDialog',
@@ -2426,7 +2498,7 @@ app.controller('ViewingController', function ($scope, $location, bridgeService,
}; };
$scope.toggleLock = function (device) { $scope.toggleLock = function (device) {
if(device.lockDeviceId) { if (device.lockDeviceId) {
device.lockDeviceId = false; device.lockDeviceId = false;
} else { } else {
device.lockDeviceId = true; device.lockDeviceId = true;
@@ -2567,9 +2639,9 @@ app.controller('StartupActionDialogCtrl', function ($scope, bridgeService, ngDia
$scope.device = $scope.bridge.device; $scope.device = $scope.bridge.device;
$scope.setDim = false; $scope.setDim = false;
var components = []; var components = [];
if($scope.device.startupActions != undefined) { if ($scope.device.startupActions != undefined) {
components = $scope.device.startupActions.split(":"); components = $scope.device.startupActions.split(":");
if(components[1] != undefined && components[1].length > 0) if (components[1] != undefined && components[1].length > 0)
$scope.setDim = true; $scope.setDim = true;
} else { } else {
components = "::".split(":"); components = "::".split(":");
@@ -2593,12 +2665,12 @@ app.controller('StartupActionDialogCtrl', function ($scope, bridgeService, ngDia
console.log("Startup action set for device called: " + device.name); console.log("Startup action set for device called: " + device.name);
ngDialog.close('ngdialog1'); ngDialog.close('ngdialog1');
var theValue = 1; var theValue = 1;
if($scope.setDim) { if ($scope.setDim) {
theValue = $scope.theState + ":" + $scope.slider.value + ":" + $scope.rgbPicker.color; theValue = $scope.theState + ":" + $scope.slider.value + ":" + $scope.rgbPicker.color;
} else { } else {
theValue = $scope.theState + "::" + $scope.rgbPicker.color; theValue = $scope.theState + "::" + $scope.rgbPicker.color;
} }
if(theValue == "::") if (theValue == "::")
theValue = ""; theValue = "";
device.startupActions = theValue; device.startupActions = theValue;
bridgeService.addDevice(device).then( bridgeService.addDevice(device).then(

View File

@@ -716,6 +716,7 @@
<th>Port (opt)</th> <th>Port (opt)</th>
<th>Username (opt)</th> <th>Username (opt)</th>
<th>Password (opt)</th> <th>Password (opt)</th>
<th>Other Types (opt)</th>
<th>Use SSL</th> <th>Use SSL</th>
<th>Manage</th> <th>Manage</th>
</tr> </tr>
@@ -732,6 +733,11 @@
<td><input id="bridge-settings-next-homegenie-password" class="form-control" <td><input id="bridge-settings-next-homegenie-password" class="form-control"
type="password" ng-model="homegenie.password" placeholder="HomeGenie password"> type="password" ng-model="homegenie.password" placeholder="HomeGenie password">
</td> </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 <td><input type="checkbox" ng-model="homegenie.secure" ng-true-value=true
ng-false-value=false></td> ng-false-value=false></td>
<td><button class="btn btn-danger" type="submit" <td><button class="btn btn-danger" type="submit"
@@ -750,10 +756,12 @@
<td><input id="bridge-settings-new-homegenie-password" class="form-control" <td><input id="bridge-settings-new-homegenie-password" class="form-control"
type="password" ng-model="newhomegeniepassword" type="password" ng-model="newhomegeniepassword"
placeholder="HomeGenie password "></td> 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 <td><input type="checkbox" ng-model="newhomegeniesecure" ng-true-value=true
ng-false-value=false></td> ng-false-value=false></td>
<td><button class="btn btn-success" type="submit" <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> </td>
</tr> </tr>
</table> </table>