Start adding UDP handling.

This commit is contained in:
Admin
2015-12-04 16:21:11 -06:00
parent 5a843f7569
commit cf772334c4
3 changed files with 21 additions and 6 deletions

View File

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

View File

@@ -39,6 +39,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.DatagramSocket;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -300,7 +301,7 @@ public class HueMulator {
else
responseString = responseString + "]";
if(device.getDeviceType().toLowerCase().contains("activity"))
if(device.getDeviceType().toLowerCase().contains("activity") || device.getMapType().equalsIgnoreCase("harmonyActivity"))
{
log.debug("executing activity to Harmony: " + url);
RunActivity anActivity = new Gson().fromJson(url, RunActivity.class);
@@ -313,7 +314,7 @@ public class HueMulator {
else
myHarmony.startActivity(anActivity);
}
else if(device.getDeviceType().toLowerCase().contains("button"))
else if(device.getDeviceType().toLowerCase().contains("button") || device.getMapType().equalsIgnoreCase("harmonyButton"))
{
log.debug("executing button press to Harmony: " + url);
ButtonPress aDeviceButton = new Gson().fromJson(url, ButtonPress.class);
@@ -326,6 +327,20 @@ public class HueMulator {
else
myHarmony.pressButton(aDeviceButton);
}
else if(url.startsWith("udp://"))
{
try {
DatagramSocket responseSocket = new DatagramSocket(10000);
String intermediate = url.substring(6);
String ipAddr = intermediate.substring(0, intermediate.indexOf(':'));
String port = intermediate.substring(intermediate.indexOf(':'), intermediate.indexOf('/'));
String theBody = intermediate.substring(intermediate.indexOf('/')+1);
responseSocket.close();
} catch (IOException e) {
log.error("Could not send UDP Datagram packet for request.", e);
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + ",\"description\": \"Error on calling out to device\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
}
}
else
{
log.debug("executing activity to Http " + (device.getHttpVerb() == null?"GET":device.getHttpVerb()) + ": " + url);

View File

@@ -287,7 +287,7 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) {
);
} else {
if(device.deviceType == null || device.deviceType == "")
device.deviceType = "switch";
device.deviceType = "custom";
if(device.httpVerb != null && device.httpVerb != "")
device.deviceType = "custom";
return $http.post(this.state.base, {
@@ -411,7 +411,7 @@ app.controller('ViewingController', function ($scope, $location, $http, $window,
app.controller('AddingController', function ($scope, $location, $http, bridgeService, BridgeSettings) {
$scope.device = {id: "", name: "", deviceType: "switch", onUrl: "", offUrl: ""};
$scope.device = {id: "", name: "", deviceType: "custom", onUrl: "", offUrl: ""};
$scope.vera = {base: "", port: "3480", id: ""};
$scope.vera.base = "http://" + BridgeSettings.veraaddress;
bridgeService.device = $scope.device;
@@ -547,7 +547,7 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
$scope.device.mapId = null;
$scope.device.name = "";
$scope.device.onUrl = "";
$scope.device.deviceType = "switch";
$scope.device.deviceType = "custom";
$scope.device.targetDevice = null;
$scope.device.offUrl = "";
$scope.device.httpVerb = null;