diff --git a/pom.xml b/pom.xml
index f6a5ebc..bb09aa3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
com.bwssystems.HABridge
ha-bridge
- 0.4.5
+ 0.4.6
jar
HA Bridge
diff --git a/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java b/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java
index cc2a8fc..b5ba80a 100644
--- a/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java
+++ b/src/main/java/com/bwssystems/HABridge/dao/DeviceDescriptor.java
@@ -11,6 +11,7 @@ public class DeviceDescriptor{
private String httpVerb;
private String contentType;
private String contentBody;
+ private String contentBodyOff;
public String getName() {
return name;
@@ -75,6 +76,14 @@ public class DeviceDescriptor{
public void setContentBody(String contentBody) {
this.contentBody = contentBody;
}
+
+ public String getContentBodyOff() {
+ return contentBodyOff;
+ }
+
+ public void setContentBodyOff(String contentBodyOff) {
+ this.contentBodyOff = contentBodyOff;
+ }
}
diff --git a/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java b/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java
index c4fc8f2..f0665b7 100644
--- a/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java
+++ b/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java
@@ -188,6 +188,9 @@ public class DeviceRepository {
} else if (name.equals("contentBody")) {
deviceEntry.setContentBody(reader.nextString());
log.debug("Read a Device - device json contentBody:" + deviceEntry.getContentBody());
+ } else if (name.equals("contentBodyOff")) {
+ deviceEntry.setContentBodyOff(reader.nextString());
+ log.debug("Read a Device - device json contentBodyOff:" + deviceEntry.getContentBodyOff());
} else {
reader.skipValue();
}
diff --git a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java
index c97cda5..96d21e3 100644
--- a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java
+++ b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java
@@ -86,6 +86,7 @@ public class DeviceResource {
deviceEntry.setHttpVerb(device.getHttpVerb());
deviceEntry.setContentType(device.getContentType());
deviceEntry.setContentBody(device.getContentBody());
+ deviceEntry.setContentBodyOff(device.getContentBodyOff());
deviceRepository.save(deviceEntry);
response.status(HttpStatus.SC_OK);
diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java
index f921af8..f48571e 100644
--- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java
+++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java
@@ -204,8 +204,12 @@ public class HueMulator {
}
//quick template
+ String body;
url = replaceIntensityValue(url, state.getBri());
- String body = replaceIntensityValue(device.getContentBody(), state.getBri());
+ if (state.isOn())
+ body = replaceIntensityValue(device.getContentBody(), state.getBri());
+ else
+ body = replaceIntensityValue(device.getContentBodyOff(), state.getBri());
//make call
if(!doHttpRequest(url, device.getHttpVerb(), device.getContentType(), body)){
response.status(HttpStatus.SC_SERVICE_UNAVAILABLE);
diff --git a/src/main/resources/public/index.html b/src/main/resources/public/index.html
index 2edd077..35f7ca2 100644
--- a/src/main/resources/public/index.html
+++ b/src/main/resources/public/index.html
@@ -36,7 +36,7 @@
diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js
index 90a24b1..c431c5b 100644
--- a/src/main/resources/public/scripts/app.js
+++ b/src/main/resources/public/scripts/app.js
@@ -156,7 +156,7 @@ app.service('bridgeService', function ($http, BridgeSettings) {
);
};
- this.addDevice = function (id, name, type, onUrl, offUrl, httpVerb, contentType, contentBody) {
+ this.addDevice = function (id, name, type, onUrl, offUrl, httpVerb, contentType, contentBody, contentBodyOff) {
this.state.error = "";
if (id) {
var putUrl = this.state.base + "/" + id;
@@ -168,7 +168,8 @@ app.service('bridgeService', function ($http, BridgeSettings) {
offUrl: offUrl,
httpVerb: httpVerb,
contentType: contentType,
- contentBody: contentBody
+ contentBody: contentBody,
+ contentBodyOff: contentBodyOff
}).then(
function (response) {
self.viewDevices();
@@ -188,7 +189,8 @@ app.service('bridgeService', function ($http, BridgeSettings) {
offUrl: offUrl,
httpVerb: httpVerb,
contentType: contentType,
- contentBody: contentBody
+ contentBody: contentBody,
+ contentBodyOff: contentBodyOff
}).then(
function (response) {
self.viewDevices();
@@ -218,12 +220,12 @@ app.service('bridgeService', function ($http, BridgeSettings) {
);
};
- this.editDevice = function (id, name, onUrl, offUrl, httpVerb, contentType, contentBody) {
- self.state.device = {id: id, name: name, onUrl: onUrl, offUrl: offUrl, httpVerb: httpVerb, contentType: contentType, contentBody: contentBody};
+ this.editDevice = function (id, name, onUrl, offUrl, httpVerb, contentType, contentBody, contentBodyOff) {
+ self.state.device = {id: id, name: name, onUrl: onUrl, offUrl: offUrl, httpVerb: httpVerb, contentType: contentType, contentBody: contentBody, contentBodyOff: contentBodyOff};
};
});
-app.controller('ViewingController', function ($scope, $location, bridgeService, BridgeSettings) {
+app.controller('ViewingController', function ($scope, $location, $http, bridgeService, BridgeSettings) {
$scope.BridgeSettings = bridgeService.BridgeSettings;
bridgeService.viewDevices();
@@ -237,20 +239,31 @@ app.controller('ViewingController', function ($scope, $location, bridgeService,
$scope.deleteDevice = function (device) {
bridgeService.deleteDevice(device.id);
};
- $scope.testUrl = function (url) {
- window.open(url, "_blank");
+ $scope.testUrl = function (device, type) {
+ if(type == "on") {
+ if(device.httpVerb == "PUT" || device.httpVerb == "POST")
+ $http.put(device.onUrl, device.contentBody);
+ else
+ window.open(device.onUrl, "_blank");
+ }
+ else {
+ if(device.httpVerb == "PUT" || device.httpVerb == "POST")
+ $http.put(device.offUrl, device.contentBodyOff);
+ else
+ window.open(device.offUrl, "_blank");
+ }
};
$scope.setBridgeUrl = function (url) {
bridgeService.state.base = url;
bridgeService.viewDevices();
};
$scope.editDevice = function (device) {
- bridgeService.editDevice(device.id, device.name, device.onUrl, device.offUrl, device.httpVerb, device.contentType, device.contentBody);
+ bridgeService.editDevice(device.id, device.name, device.onUrl, device.offUrl, device.httpVerb, device.contentType, device.contentBody, device.contentBodyOff);
$location.path('/editdevice');
};
});
-app.controller('AddingController', function ($scope, $location, bridgeService, BridgeSettings) {
+app.controller('AddingController', function ($scope, $location, $http, bridgeService, BridgeSettings) {
$scope.device = {id: "", name: "", deviceType: "switch", onUrl: "", offUrl: ""};
$scope.vera = {base: "", port: "3480", id: ""};
@@ -321,11 +334,22 @@ app.controller('AddingController', function ($scope, $location, bridgeService, B
};
$scope.testUrl = function (url) {
- window.open(url, "_blank");
+ if(type == "on") {
+ if(device.httpVerb == "PUT" || device.httpVerb == "POST")
+ $http.put(device.onUrl, device.contentBody);
+ else
+ window.open(device.onUrl, "_blank");
+ }
+ else {
+ if(device.httpVerb == "PUT" || device.httpVerb == "POST")
+ $http.put(device.offUrl, device.contentBodyOff);
+ else
+ window.open(device.offUrl, "_blank");
+ }
};
$scope.addDevice = function () {
- bridgeService.addDevice($scope.device.id, $scope.device.name, $scope.device.deviceType, $scope.device.onUrl, $scope.device.offUrl, $scope.device.httpVerb, $scope.device.contentType, $scope.device.contentBody).then(
+ bridgeService.addDevice($scope.device.id, $scope.device.name, $scope.device.deviceType, $scope.device.onUrl, $scope.device.offUrl, $scope.device.httpVerb, $scope.device.contentType, $scope.device.contentBody, $scope.device.contentBodyOff).then(
function () {
$scope.device.id = "";
$scope.device.name = "";
@@ -335,6 +359,7 @@ app.controller('AddingController', function ($scope, $location, bridgeService, B
$scope.device.httpVerb = null;
$scope.device.contentType = null;
$scope.device.contentBody = null;
+ $scope.device.contentBodyOff = null;
$location.path('/#');
},
function (error) {
diff --git a/src/main/resources/public/views/configuration.html b/src/main/resources/public/views/configuration.html
index be7d237..aee3f9a 100644
--- a/src/main/resources/public/views/configuration.html
+++ b/src/main/resources/public/views/configuration.html
@@ -107,9 +107,9 @@
{{device.deviceType}} |
+ ng-click="testUrl(device, 'on')">Test ON
+ ng-click="testUrl(device, 'off')">Test OFF
@@ -49,7 +49,7 @@
Test
+ ng-click="testUrl(device, 'off')">Test
+
Test
+ ng-click="testUrl(device, 'on')">Test
@@ -100,7 +100,7 @@
Test
+ ng-click="testUrl(device, 'off')">Test
+
Test
+ ng-click="testUrl(device, 'on')">Test
@@ -94,7 +94,7 @@
Test
+ ng-click="testUrl(device, 'off')">Test
diff --git a/src/main/resources/public/views/verascene.html b/src/main/resources/public/views/verascene.html
index ac2ab87..7a6d7ae 100644
--- a/src/main/resources/public/views/verascene.html
+++ b/src/main/resources/public/views/verascene.html
@@ -75,7 +75,7 @@
Test
+ ng-click="testUrl(device, 'on')">Test
@@ -89,7 +89,7 @@
Test
+ ng-click="testUrl(device, 'off')">Test
|