Skip to content

Commit 86a931d

Browse files
committed
added exec:// type for loops. updated button maptypeid naming.
Fixes #114 Fixes #115
1 parent 3e89072 commit 86a931d

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ tcp://192.168.5.5:110000/0x
151151
```
152152

153153
#### Multiple Call Construct
154-
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.
154+
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.
155155
Format Example in the URL areas:
156156
```
157157
[{"item":"http://192.168.1.1:8180/do/this/thing"},
@@ -165,7 +165,8 @@ Format Example in the URL areas:
165165
[{"item":"udp://192.168.1.1:5000/0x450555"},
166166
{"item":"http://192.168.1.1:8180/do/this/thing"},
167167
{"item":"tcp://192.168.2.1/sendthisdata"},
168-
{"item":"https://192.168.12.1/do/this/secure/thing"}]
168+
{"item":"https://192.168.12.1/do/this/secure/thing"},
169+
{"item":"exec://notepad.exe"}]
169170
```
170171
#### Script or Command Execution
171172
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
185186
186187
/home/me/startsomething.sh
187188
189+
OR
190+
191+
[{"item":"exec://notepad.exe"}]
192+
188193
```
189194

190195
Also, you may want to use the REST API's listed below to configure your devices.

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.bwssystems.HABridge</groupId>
77
<artifactId>ha-bridge</artifactId>
8-
<version>2.0.5</version>
8+
<version>2.0.6</version>
99
<packaging>jar</packaging>
1010

1111
<name>HA Bridge</name>

src/main/java/com/bwssystems/HABridge/hue/HueMulator.java

+32-10
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ else if(!responseString.contains("[{\"error\":"))
428428
else
429429
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"No HUE configured\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
430430

431-
return responseString;
431+
return responseString;
432432
}
433433

434434
if(stateHasBri)
@@ -570,18 +570,19 @@ else if(device.getDeviceType().startsWith("exec")) {
570570
if( i > 0) {
571571
Thread.sleep(bridgeSettings.getButtonsleep());
572572
}
573-
try {
574-
log.debug("Executing request: " + callItems[i].getItem());
575-
Process p = Runtime.getRuntime().exec(replaceIntensityValue(callItems[i].getItem(), state.getBri(), false));
576-
log.debug("Process running: " + p.isAlive());
577-
} catch (IOException e) {
578-
log.warn("Could not execute request: " + callItems[i].getItem(), e);
579-
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling out to device\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
573+
String intermediate;
574+
if(callItems[i].getItem().contains("exec://"))
575+
intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
576+
else
577+
intermediate = callItems[i].getItem();
578+
String anError = doExecRequest(intermediate, state, lightId);
579+
if(anError != null) {
580+
responseString = anError;
580581
i = callItems.length+1;
581-
}
582+
}
582583
}
583584
}
584-
else // This section allows the usage of http/tcp/udp calls in a given set of items
585+
else // This section allows the usage of http/tcp/udp/exec calls in a given set of items
585586
{
586587
log.debug("executing HUE api request for network call: " + url);
587588
if(!url.startsWith("[")) {
@@ -634,6 +635,14 @@ else if(callItems[i].getItem().contains("tcp://"))
634635
dataSendSocket.close();
635636
}
636637
}
638+
else if(callItems[i].getItem().contains("exec://")) {
639+
String intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
640+
String anError = doExecRequest(intermediate, state, lightId);
641+
if(anError != null) {
642+
responseString = anError;
643+
i = callItems.length+1;
644+
}
645+
}
637646
else {
638647
log.debug("executing HUE api request to Http " + (device.getHttpVerb() == null?"GET":device.getHttpVerb()) + ": " + callItems[i].getItem());
639648

@@ -781,6 +790,19 @@ protected String doHttpRequest(String url, String httpVerb, String contentType,
781790
}
782791
return theContent;
783792
}
793+
794+
private String doExecRequest(String anItem, DeviceState state, String lightId) {
795+
log.debug("Executing request: " + anItem);
796+
String responseString = null;
797+
try {
798+
Process p = Runtime.getRuntime().exec(replaceIntensityValue(anItem, state.getBri(), false));
799+
log.debug("Process running: " + p.isAlive());
800+
} catch (IOException e) {
801+
log.warn("Could not execute request: " + anItem, e);
802+
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling out to device\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
803+
}
804+
return responseString;
805+
}
784806

785807
private String formatSuccessHueResponse(DeviceState state, String body, boolean stateHasOn, String lightId) {
786808

src/main/resources/public/scripts/app.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ app.controller('HarmonyController', function ($scope, $location, $http, bridgeSe
994994
var actionOn = angular.fromJson(onbutton);
995995
var actionOff = angular.fromJson(offbutton);
996996
if( $scope.device.mapType == "harmonyButton") {
997+
$scope.device.mapId = $scope.device.mapId + "-" + actionOn.command;
997998
$scope.device.onUrl = currentOn.substr(0, currentOn.indexOf("]")) + ",{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOn.command + "\"}]";
998999
$scope.device.offUrl = currentOff.substr(0, currentOff.indexOf("]")) + ",{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOff.command + "\"}]";
9991000
}
@@ -1002,7 +1003,7 @@ app.controller('HarmonyController', function ($scope, $location, $http, bridgeSe
10021003
$scope.device.targetDevice = harmonydevice.hub;
10031004
$scope.device.name = harmonydevice.device.label;
10041005
$scope.device.mapType = "harmonyButton";
1005-
$scope.device.mapId = harmonydevice.device.id + "-" + actionOn.command + "-" + actionOff.command;
1006+
$scope.device.mapId = harmonydevice.device.id + "-" + actionOn.command;
10061007
$scope.device.onUrl = "[{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOn.command + "\"}]";
10071008
$scope.device.offUrl = "[{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOff.command + "\"}]";
10081009
}

0 commit comments

Comments
 (0)