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

@@ -250,6 +250,8 @@ The default location for the configuration file to contain the settings for the
The default location for the db to contain the devices as they are added is "data/devices.db". If you would like a different filename or directory, specify `<directory>/<filename> explicitly.
#### UPNP IP Address
The server defaults to the first available address on the host if this is not given. This default may NOT be the correct IP that is your public IP for your host on the network. It is best to set this parameter to not have discovery issues. Replace this value with the server ipv4 address you would like to use as the address that any upnp device will call after discovery.
#### Use UPNP Address Interface
The server tries to bind to all interfaces to respond to UPNP request. Setting this to `true` will make the binding to the interface that has the `UPNP IP Address`. The default is to be all interfaces which is set as false.
#### Web Server IP Address
The server defaults to all interfaces on the machine (0.0.0.0). Replace this value with the server ipv4 address you would like to use as the address that will bind to a specific ip address on an interface if you would like. This is only necessary if you want to isolate how access is handled to the web UI.
#### Web Server Port
@@ -408,7 +410,7 @@ You can control items that require special calculated values using ${intensity.m
For the items that want to have a date time put into the message, utilize ${time.format(yyyy-MM-ddTHH:mm:ssXXX)} where "yyyy-MM-ddTHH:mm:ssXXX" can be any format from the Java SimpleDateFormat documented here: https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
Also, device data can be inserted into your payloads by the use of "${device.name}", "${device.id}", "${device.uniqueid}", "${device.targetDevice}", "${device.mapId}", "${device.mapType}" and "${device.deviceType}". These work just like the dimming value replacements.
Also, device data can be inserted into your payloads by the use of "${device.name}", "${device.id}", "${device.uniqueid}", "${device.targetDevice}", "${device.mapId}", "${device.mapType}", "${device.deviceType}", "${device.requesterAddress}", "${device.description}" and "${device.comments}". These work just like the dimming value replacements.
e.g.
```
[{"item":"http://192.168.1.201:3480/data_request?id=action&output_format=json&DeviceNum=10&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=${intensity.math(X/4)}","type":"httpDevice"}]

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>4.5.1a</version>
<version>4.5.1b</version>
<packaging>jar</packaging>
<name>HA Bridge</name>

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"