Fixed HAL control issue, added switch status, added new ${device.xxx}

replacement items and interface selection for upnp
This commit is contained in:
Admin
2017-06-09 12:57:18 -05:00
parent 998450af4e
commit 208b1cad2a
10 changed files with 72 additions and 10 deletions

View File

@@ -12,6 +12,9 @@ public class BridgeSettingsDescriptor {
@SerializedName("upnpconfigaddress")
@Expose
private String upnpconfigaddress;
@SerializedName("useupnpiface")
@Expose
private boolean useupnpiface;
@SerializedName("serverport")
@Expose
private Integer serverport;
@@ -104,6 +107,7 @@ public class BridgeSettingsDescriptor {
public BridgeSettingsDescriptor() {
super();
this.upnpstrict = true;
this.useupnpiface = false;
this.traceupnp = false;
this.nestconfigured = false;
this.veraconfigured = false;
@@ -113,8 +117,12 @@ public class BridgeSettingsDescriptor {
this.halconfigured = false;
this.mqttconfigured = false;
this.hassconfigured = false;
this.domoticzconfigured = false;
this.somfyconfigured = false;
this.lifxconfigured = false;
this.farenheit = true;
this.whitelist = null;
this.securityData = null;
this.settingsChanged = false;
this.myechourl = "echo.amazon.com/#cards";
this.webaddress = "0.0.0.0";
@@ -126,6 +134,12 @@ public class BridgeSettingsDescriptor {
public void setUpnpConfigAddress(String upnpConfigAddress) {
this.upnpconfigaddress = upnpConfigAddress;
}
public boolean isUseupnpiface() {
return useupnpiface;
}
public void setUseupnpiface(boolean useupnpiface) {
this.useupnpiface = useupnpiface;
}
public Integer getServerPort() {
return serverport;
}

View File

@@ -74,7 +74,8 @@ public class DeviceDescriptor{
@SerializedName("comments")
@Expose
private String comments;
@SerializedName("deviceState")
@Expose
private DeviceState deviceState;
public String getName() {

View File

@@ -61,6 +61,7 @@ public class DeviceRepository extends BackupHandler {
{
DeviceDescriptor list[] = gson.fromJson(jsonContent, DeviceDescriptor[].class);
for(int i = 0; i < list.length; i++) {
list[i].setDeviceState(null);
put(list[i].getId(), list[i]);
if(Integer.decode(list[i].getId()) > nextId) {
nextId = Integer.decode(list[i].getId());

View File

@@ -14,6 +14,9 @@ public class DeviceDataDecode {
private static final String DEVICE_MAPTYPE = "${device.mapType}";
private static final String DEVICE_DEVICETYPE = "${device.deviceType}";
private static final String DEVICE_TARGETDEVICE = "${device.targetDevice}";
private static final String DEVICE_REQUESTERADDRESS = "${device.requesterAddress}";
private static final String DEVICE_DESCRIPTION = "${device.description}";
private static final String DEVICE_COMMENTS = "${device.comments}";
public static String replaceDeviceData(String request, DeviceDescriptor device) {
if (request == null) {
@@ -58,6 +61,21 @@ public class DeviceDataDecode {
notDone = true;
}
if (request.contains(DEVICE_REQUESTERADDRESS)) {
request = request.replace(DEVICE_REQUESTERADDRESS, device.getRequesterAddress());
notDone = true;
}
if (request.contains(DEVICE_DESCRIPTION)) {
request = request.replace(DEVICE_DESCRIPTION, device.getDescription());
notDone = true;
}
if (request.contains(DEVICE_COMMENTS)) {
request = request.replace(DEVICE_COMMENTS, device.getComments());
notDone = true;
}
log.debug("Request <<" + request + ">>, not done: " + notDone);
}
return request;

View File

@@ -112,19 +112,20 @@ public class HalHome implements Home {
@Override
public String deviceHandler(CallItem anItem, MultiCommandUtil aMultiUtil, String lightId, int intensity,
Integer targetBri,Integer targetBriInc, DeviceDescriptor device, String body) {
boolean halFound = false;
String responseString = null;
String theUrl = anItem.getItem().getAsString();
if(theUrl != null && !theUrl.isEmpty () && theUrl.contains("http")) {
String intermediate = theUrl.substring(theUrl.indexOf("://") + 3);
String hostPortion = intermediate.substring(0, intermediate.indexOf('/'));
// String theUrlBody = intermediate.substring(intermediate.indexOf('/') + 1);
String hostAddr = null;
// String hostAddr = null;
// String port = null;
if (hostPortion.contains(":")) {
hostAddr = hostPortion.substring(0, intermediate.indexOf(':'));
// if (hostPortion.contains(":")) {
// hostAddr = hostPortion.substring(0, intermediate.indexOf(':'));
// port = hostPortion.substring(intermediate.indexOf(':') + 1);
} else
hostAddr = hostPortion;
// } else
// hostAddr = hostPortion;
log.debug("executing HUE api request to Http "
+ (anItem.getHttpVerb() == null ? "GET" : anItem.getHttpVerb()) + ": "
+ anItem.getItem().getAsString());
@@ -137,7 +138,8 @@ public class HalHome implements Home {
for (Map.Entry<String, HalInfo> entry : hals.entrySet())
{
if(entry.getValue().getHalAddress().getIp().equals(hostAddr)) {
if(entry.getValue().getHalAddress().getIp().equals(hostPortion)) {
halFound = true;
if(entry.getValue().getHalAddress().getSecure()!= null && entry.getValue().getHalAddress().getSecure())
anUrl = "https://" + anUrl;
else
@@ -146,6 +148,10 @@ public class HalHome implements Home {
if(!anUrl.contains("?Token="))
anUrl = anUrl + "?Token=" + entry.getValue().getHalAddress().getPassword();
log.debug("executing HUE api request to Http "
+ (anItem.getHttpVerb() == null ? "GET" : anItem.getHttpVerb()) + ": "
+ anUrl);
if (entry.getValue().deviceCommand(anUrl) == null) {
log.warn("Error on calling hal to change device state: " + anUrl);
responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId,
@@ -155,6 +161,13 @@ public class HalHome implements Home {
}
}
}
if(!halFound) {
log.warn("No HAL found to call: " + theUrl);
responseString = new Gson().toJson(HueErrorResponse.createResponse("6", "/lights/" + lightId,
"No HAL found.", "/lights/"
+ lightId + "state", null, null).getTheErrors(), HueError[].class);
}
return responseString;
}

View File

@@ -25,6 +25,7 @@ public class UpnpListener {
private String responseAddress;
private boolean strict;
private boolean traceupnp;
private boolean useUpnpIface;
private BridgeControlDescriptor bridgeControl;
private String bridgeId;
private String bridgeSNUUID;
@@ -74,6 +75,7 @@ public class UpnpListener {
responseAddress = theSettings.getUpnpConfigAddress();
strict = theSettings.isUpnpStrict();
traceupnp = theSettings.isTraceupnp();
useUpnpIface = theSettings.isUseupnpiface();
bridgeControl = theControl;
aHueConfig = HuePublicConfig.createConfig("temp", responseAddress, HueConstants.HUB_VERSION);
bridgeId = aHueConfig.getBridgeid();
@@ -114,7 +116,10 @@ public class UpnpListener {
else
log.debug(name + " ... has addr " + addr);
if (InetAddressUtils.isIPv4Address(addr.getHostAddress())) {
IPsPerNic++;
if(!useUpnpIface)
IPsPerNic++;
else if(addr.getHostAddress().equals(responseAddress))
IPsPerNic++;
}
}
log.debug("Checking " + name + " to our interface set");

View File

@@ -43,6 +43,7 @@
<th sortable-header col="id" comparator-fn="comparatorUniqueId">ID</th>
<th sortable-header col="name">Name</th>
<th sortable-header col="description">Description</th>
<th sortable-header col="devicestate">Device State</th>
<th sortable-header col="deviceType">Type</th>
<th sortable-header col="targetDevice">Target</th>
<th sortable-header col="inactive">Inactive</th>
@@ -55,6 +56,7 @@
<td>{{device.id}}</td>
<td>{{device.name}}</td>
<td class="cr">{{device.description}}</td>
<td class="cr">on={{device.deviceState.on}},bri={{device.deviceState.on}},hue={{device.deviceState.hue}},sat={{device.deviceState.sat}},effect={{device.deviceState.effect}},ct={{device.deviceState.ct}},alert={{device.deviceState.alert}},colormode={{device.deviceState.colormode}},reachable={{device.deviceState.reachable}},XYList={{device.deviceState.xy}}</td>
<td>{{device.deviceType}}</td>
<td>{{device.targetDevice}}</td>
<td>{{device.inactive}}</td>

View File

@@ -82,6 +82,12 @@
ng-model="bridge.settings.upnpconfigaddress"
placeholder="192.168.1.1"></td>
</tr>
<tr>
<td>Use UPNP Address Interface Only</td>
<td><input type="checkbox"
ng-model="bridge.settings.useupnpiface" ng-true-value=true
ng-false-value=false> {{bridge.settings.useupnpiface}}</td>
</tr>
<tr>
<td>Web Server IP Address</td>
<td><input id="bridge-settings-webaddress"