mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-19 08:28:46 +00:00
added multiple command execution. Added commandline Exec. NEeds testing
This commit is contained in:
13
src/main/java/com/bwssystems/HABridge/api/CallItem.java
Normal file
13
src/main/java/com/bwssystems/HABridge/api/CallItem.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package com.bwssystems.HABridge.api;
|
||||||
|
|
||||||
|
public class CallItem {
|
||||||
|
private String Item;
|
||||||
|
|
||||||
|
public String getItem() {
|
||||||
|
return Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItem(String item) {
|
||||||
|
Item = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.bwssystems.HABridge.hue;
|
package com.bwssystems.HABridge.hue;
|
||||||
|
|
||||||
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
||||||
|
import com.bwssystems.HABridge.api.CallItem;
|
||||||
import com.bwssystems.HABridge.api.UserCreateRequest;
|
import com.bwssystems.HABridge.api.UserCreateRequest;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceResponse;
|
import com.bwssystems.HABridge.api.hue.DeviceResponse;
|
||||||
import com.bwssystems.HABridge.api.hue.DeviceState;
|
import com.bwssystems.HABridge.api.hue.DeviceState;
|
||||||
@@ -510,11 +511,22 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(url.startsWith("udp://"))
|
else if(device.getDeviceType().startsWith("Exec")) {
|
||||||
|
Process p = Runtime.getRuntime().exec(url);
|
||||||
|
}
|
||||||
|
else if(url.contains("udp://"))
|
||||||
{
|
{
|
||||||
|
if(!url.substring(0, 1).equalsIgnoreCase("[")) {
|
||||||
|
url = "[{\"item\":\"" + url +"\"}]";
|
||||||
|
}
|
||||||
|
CallItem[] callItems = new Gson().fromJson(url, CallItem[].class);
|
||||||
log.debug("executing HUE api request to UDP: " + url);
|
log.debug("executing HUE api request to UDP: " + url);
|
||||||
|
for(int i = 0; i < callItems.length; i++) {
|
||||||
|
if( i > 0) {
|
||||||
|
Thread.sleep(bridgeSettings.getButtonsleep());
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
String intermediate = url.substring(6);
|
String intermediate = callItems[i].getItem().substring(6);
|
||||||
String ipAddr = intermediate.substring(0, intermediate.indexOf(':'));
|
String ipAddr = intermediate.substring(0, intermediate.indexOf(':'));
|
||||||
String port = intermediate.substring(intermediate.indexOf(':') + 1, intermediate.indexOf('/'));
|
String port = intermediate.substring(intermediate.indexOf(':') + 1, intermediate.indexOf('/'));
|
||||||
String theBody = intermediate.substring(intermediate.indexOf('/')+1);
|
String theBody = intermediate.substring(intermediate.indexOf('/')+1);
|
||||||
@@ -533,22 +545,32 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling out to device\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
|
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling out to device\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if(!url.substring(0, 1).equalsIgnoreCase("[")) {
|
||||||
|
url = "[{\"item\":\"" + url +"\"}]";
|
||||||
|
}
|
||||||
|
CallItem[] callItems = new Gson().fromJson(url, CallItem[].class);
|
||||||
log.debug("executing HUE api request to Http " + (device.getHttpVerb() == null?"GET":device.getHttpVerb()) + ": " + url);
|
log.debug("executing HUE api request to Http " + (device.getHttpVerb() == null?"GET":device.getHttpVerb()) + ": " + url);
|
||||||
|
for(int i = 0; i < callItems.length; i++) {
|
||||||
|
if( i > 0) {
|
||||||
|
Thread.sleep(bridgeSettings.getButtonsleep());
|
||||||
|
}
|
||||||
// quick template
|
// quick template
|
||||||
String body;
|
String body;
|
||||||
url = replaceIntensityValue(url, state.getBri());
|
String anUrl = replaceIntensityValue(callItems[i].getItem(), state.getBri());
|
||||||
if (state.isOn())
|
if (state.isOn())
|
||||||
body = replaceIntensityValue(device.getContentBody(), state.getBri());
|
body = replaceIntensityValue(device.getContentBody(), state.getBri());
|
||||||
else
|
else
|
||||||
body = replaceIntensityValue(device.getContentBodyOff(), state.getBri());
|
body = replaceIntensityValue(device.getContentBodyOff(), state.getBri());
|
||||||
// make call
|
// make call
|
||||||
if (doHttpRequest(url, device.getHttpVerb(), device.getContentType(), body) == null) {
|
if (doHttpRequest(anUrl, device.getHttpVerb(), device.getContentType(), body) == null) {
|
||||||
log.warn("Error on calling url to change device state: " + url);
|
log.warn("Error on calling url to change device state: " + anUrl);
|
||||||
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling url to change device state\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
|
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling url to change device state\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!responseString.contains("[{\"error\":")) {
|
if(!responseString.contains("[{\"error\":")) {
|
||||||
device.setDeviceState(state);
|
device.setDeviceState(state);
|
||||||
|
|||||||
@@ -1147,7 +1147,7 @@ app.controller('HueController', function ($scope, $location, $http, bridgeServic
|
|||||||
$scope.device.contentType = "application/json";
|
$scope.device.contentType = "application/json";
|
||||||
$scope.device.mapType = "hueDevice";
|
$scope.device.mapType = "hueDevice";
|
||||||
$scope.device.mapId = huedevice.device.uniqueid;
|
$scope.device.mapId = huedevice.device.uniqueid;
|
||||||
$scope.device.onUrl = "{\"ipAddress\":\"" + huedevice.hueaddress + "\",\"deviceId\":\"" + huedevice.device.uniqueid +"\"}";
|
$scope.device.onUrl = "{\"ipAddress\":\"" + huedevice.hueaddress + "\",\"deviceId\":\"" + huedevice.huedeviceid +"\"}";
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.addDevice = function () {
|
$scope.addDevice = function () {
|
||||||
|
|||||||
@@ -78,7 +78,10 @@
|
|||||||
<h2 class="panel-title">Add a new device</h2>
|
<h2 class="panel-title">Add a new device</h2>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-muted">This area allows you to create any http or udp call to an endpoint. You can use the default GET or select
|
<p class="text-muted">This area allows you to create any http or udp call to an endpoint. You can use the default GET or select
|
||||||
the http verb type below and configure a payload for either on or off methods. Currently, https is not supported.</p>
|
the http verb type below and configure a payload for either on, dim or off methods. Currently, https is not supported. For Execution of
|
||||||
|
a script or program, plese fill in the path. All manually entered calls can use Json notation of array with
|
||||||
|
[{"item":"the payload"},{"item":"another payload"}] to execute multiple entries. Adding the value replacements (${intensity..byte},${intensity.percent},${intensity.math(X*1)})
|
||||||
|
will also work.</p>
|
||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<form class="form-horizontal">
|
<form class="form-horizontal">
|
||||||
@@ -95,6 +98,20 @@
|
|||||||
Add Bridge Device</button>
|
Add Bridge Device</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="row">
|
||||||
|
<label class="col-xs-12 col-sm-2 control-label" for="device-type">Device Type
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div class="col-xs-8 col-sm-7">
|
||||||
|
<select name="device-type" id="device-type" ng-model="device.deviceType">
|
||||||
|
<option value="">---Types if needed---</option> <!-- not selected / blank option -->
|
||||||
|
<option value="UDP">UDP</option>
|
||||||
|
<option value="Exec">Execute Script/Program</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<label class="col-xs-12 col-sm-2 control-label" for="device-on-url">On
|
<label class="col-xs-12 col-sm-2 control-label" for="device-on-url">On
|
||||||
|
|||||||
Reference in New Issue
Block a user