mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 16:17:30 +00:00
added exec:// type for loops. updated button maptypeid naming.
Fixes #114 Fixes #115
This commit is contained in:
@@ -151,7 +151,7 @@ tcp://192.168.5.5:110000/0x
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### Multiple Call Construct
|
#### 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:
|
Format Example in the URL areas:
|
||||||
```
|
```
|
||||||
[{"item":"http://192.168.1.1:8180/do/this/thing"},
|
[{"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":"udp://192.168.1.1:5000/0x450555"},
|
||||||
{"item":"http://192.168.1.1:8180/do/this/thing"},
|
{"item":"http://192.168.1.1:8180/do/this/thing"},
|
||||||
{"item":"tcp://192.168.2.1/sendthisdata"},
|
{"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
|
#### 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.
|
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
|
/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.
|
Also, you may want to use the REST API's listed below to configure your devices.
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>com.bwssystems.HABridge</groupId>
|
<groupId>com.bwssystems.HABridge</groupId>
|
||||||
<artifactId>ha-bridge</artifactId>
|
<artifactId>ha-bridge</artifactId>
|
||||||
<version>2.0.5</version>
|
<version>2.0.6</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HA Bridge</name>
|
<name>HA Bridge</name>
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
else
|
else
|
||||||
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"No HUE configured\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
|
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"No HUE configured\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
|
||||||
|
|
||||||
return responseString;
|
return responseString;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(stateHasBri)
|
if(stateHasBri)
|
||||||
@@ -570,18 +570,19 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
if( i > 0) {
|
if( i > 0) {
|
||||||
Thread.sleep(bridgeSettings.getButtonsleep());
|
Thread.sleep(bridgeSettings.getButtonsleep());
|
||||||
}
|
}
|
||||||
try {
|
String intermediate;
|
||||||
log.debug("Executing request: " + callItems[i].getItem());
|
if(callItems[i].getItem().contains("exec://"))
|
||||||
Process p = Runtime.getRuntime().exec(replaceIntensityValue(callItems[i].getItem(), state.getBri(), false));
|
intermediate = callItems[i].getItem().substring(callItems[i].getItem().indexOf("://") + 3);
|
||||||
log.debug("Process running: " + p.isAlive());
|
else
|
||||||
} catch (IOException e) {
|
intermediate = callItems[i].getItem();
|
||||||
log.warn("Could not execute request: " + callItems[i].getItem(), e);
|
String anError = doExecRequest(intermediate, state, lightId);
|
||||||
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling out to device\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
|
if(anError != null) {
|
||||||
|
responseString = anError;
|
||||||
i = callItems.length+1;
|
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);
|
log.debug("executing HUE api request for network call: " + url);
|
||||||
if(!url.startsWith("[")) {
|
if(!url.startsWith("[")) {
|
||||||
@@ -634,6 +635,14 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
dataSendSocket.close();
|
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 {
|
else {
|
||||||
log.debug("executing HUE api request to Http " + (device.getHttpVerb() == null?"GET":device.getHttpVerb()) + ": " + callItems[i].getItem());
|
log.debug("executing HUE api request to Http " + (device.getHttpVerb() == null?"GET":device.getHttpVerb()) + ": " + callItems[i].getItem());
|
||||||
|
|
||||||
@@ -782,6 +791,19 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
return theContent;
|
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) {
|
private String formatSuccessHueResponse(DeviceState state, String body, boolean stateHasOn, String lightId) {
|
||||||
|
|
||||||
String responseString = "[";
|
String responseString = "[";
|
||||||
|
|||||||
@@ -994,6 +994,7 @@ app.controller('HarmonyController', function ($scope, $location, $http, bridgeSe
|
|||||||
var actionOn = angular.fromJson(onbutton);
|
var actionOn = angular.fromJson(onbutton);
|
||||||
var actionOff = angular.fromJson(offbutton);
|
var actionOff = angular.fromJson(offbutton);
|
||||||
if( $scope.device.mapType == "harmonyButton") {
|
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.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 + "\"}]";
|
$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.targetDevice = harmonydevice.hub;
|
||||||
$scope.device.name = harmonydevice.device.label;
|
$scope.device.name = harmonydevice.device.label;
|
||||||
$scope.device.mapType = "harmonyButton";
|
$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.onUrl = "[{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOn.command + "\"}]";
|
||||||
$scope.device.offUrl = "[{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOff.command + "\"}]";
|
$scope.device.offUrl = "[{\"device\":\"" + harmonydevice.device.id + "\",\"button\":\"" + actionOff.command + "\"}]";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user