Compare commits

...

1 Commits

Author SHA1 Message Date
Admin
86a931d383 added exec:// type for loops. updated button maptypeid naming.
Fixes #114
Fixes #115
2016-05-11 12:23:43 -05:00
4 changed files with 42 additions and 14 deletions

View File

@@ -151,7 +151,7 @@ tcp://192.168.5.5:110000/0x
```
#### Multiple Call Construct
Also available is the ability to specify multiple commands in the On URL, Dim URL and Off URL areas by adding Json constructs listed here.
Also available is the ability to specify multiple commands in the On URL, Dim URL and Off URL areas by adding Json constructs listed here. This is only for the types of tcp, udp, http, https or a new exec type.
Format Example in the URL areas:
```
[{"item":"http://192.168.1.1:8180/do/this/thing"},
@@ -165,7 +165,8 @@ Format Example in the URL areas:
[{"item":"udp://192.168.1.1:5000/0x450555"},
{"item":"http://192.168.1.1:8180/do/this/thing"},
{"item":"tcp://192.168.2.1/sendthisdata"},
{"item":"https://192.168.12.1/do/this/secure/thing"}]
{"item":"https://192.168.12.1/do/this/secure/thing"},
{"item":"exec://notepad.exe"}]
```
#### Script or Command Execution
The release as of v2.0.0 will now support the execution of a local script or program. This will blindly fire off a process to run and is bound by the privileges of the java process.
@@ -185,6 +186,10 @@ OR
/home/me/startsomething.sh
OR
[{"item":"exec://notepad.exe"}]
```
Also, you may want to use the REST API's listed below to configure your devices.

View File

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

View File

@@ -428,7 +428,7 @@ public class HueMulator implements HueErrorStringSet {
else
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"No HUE configured\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
return responseString;
return responseString;
}
if(stateHasBri)
@@ -570,18 +570,19 @@ public class HueMulator implements HueErrorStringSet {
if( i > 0) {
Thread.sleep(bridgeSettings.getButtonsleep());
}
try {
log.debug("Executing request: " + callItems[i].getItem());
Process p = Runtime.getRuntime().exec(replaceIntensityValue(callItems[i].getItem(), state.getBri(), false));
log.debug("Process running: " + p.isAlive());
} catch (IOException e) {
log.warn("Could not execute request: " + callItems[i].getItem(), e);
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling out to device\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
String intermediate;
if(callItems[i].getItem().contains("exec://"))
intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
else
intermediate = callItems[i].getItem();
String anError = doExecRequest(intermediate, state, lightId);
if(anError != null) {
responseString = anError;
i = callItems.length+1;
}
}
}
}
else // This section allows the usage of http/tcp/udp calls in a given set of items
else // This section allows the usage of http/tcp/udp/exec calls in a given set of items
{
log.debug("executing HUE api request for network call: " + url);
if(!url.startsWith("[")) {
@@ -634,6 +635,14 @@ public class HueMulator implements HueErrorStringSet {
dataSendSocket.close();
}
}
else if(callItems[i].getItem().contains("exec://")) {
String intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
String anError = doExecRequest(intermediate, state, lightId);
if(anError != null) {
responseString = anError;
i = callItems.length+1;
}
}
else {
log.debug("executing HUE api request to Http " + (device.getHttpVerb() == null?"GET":device.getHttpVerb()) + ": " + callItems[i].getItem());
@@ -781,6 +790,19 @@ public class HueMulator implements HueErrorStringSet {
}
return theContent;
}
private String doExecRequest(String anItem, DeviceState state, String lightId) {
log.debug("Executing request: " + anItem);
String responseString = null;
try {
Process p = Runtime.getRuntime().exec(replaceIntensityValue(anItem, state.getBri(), false));
log.debug("Process running: " + p.isAlive());
} catch (IOException e) {
log.warn("Could not execute request: " + anItem, e);
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling out to device\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
}
return responseString;
}
private String formatSuccessHueResponse(DeviceState state, String body, boolean stateHasOn, String lightId) {

View File

@@ -994,6 +994,7 @@ app.controller('HarmonyController', function ($scope, $location, $http, bridgeSe
var actionOn = angular.fromJson(onbutton);
var actionOff = angular.fromJson(offbutton);
if( $scope.device.mapType == "harmonyButton") {
$scope.device.mapId = $scope.device.mapId + "-" + actionOn.command;
$scope.device.onUrl = currentOn.substr(0, currentOn.indexOf("]")) + ",{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOn.command + "\"}]";
$scope.device.offUrl = currentOff.substr(0, currentOff.indexOf("]")) + ",{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOff.command + "\"}]";
}
@@ -1002,7 +1003,7 @@ app.controller('HarmonyController', function ($scope, $location, $http, bridgeSe
$scope.device.targetDevice = harmonydevice.hub;
$scope.device.name = harmonydevice.device.label;
$scope.device.mapType = "harmonyButton";
$scope.device.mapId = harmonydevice.device.id + "-" + actionOn.command + "-" + actionOff.command;
$scope.device.mapId = harmonydevice.device.id + "-" + actionOn.command;
$scope.device.onUrl = "[{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOn.command + "\"}]";
$scope.device.offUrl = "[{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOff.command + "\"}]";
}