mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-16 18:24:36 +00:00
Updated test methods for special PUT/POST calls. Cleaned up device.db
file write to not keep junk around.
This commit is contained in:
@@ -3,6 +3,8 @@ package com.bwssystems.HABridge.dao;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
import java.nio.file.FileSystem;
|
||||||
|
import java.nio.file.FileSystems;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
@@ -106,7 +108,10 @@ public class DeviceRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Path target = FileSystems.getDefault().getPath("data", "device.db.old");
|
||||||
|
Files.move(filePath, target);
|
||||||
Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE);
|
Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE);
|
||||||
|
Files.delete(target);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Error writing the file: " + filePath + " message: " + e.getMessage(), e);
|
log.error("Error writing the file: " + filePath + " message: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,6 +182,8 @@ app.service('bridgeService', function ($http, BridgeSettings) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
if(type == null || type == "")
|
||||||
|
type = "switch";
|
||||||
return $http.post(this.state.base, {
|
return $http.post(this.state.base, {
|
||||||
name: name,
|
name: name,
|
||||||
deviceType: type,
|
deviceType: type,
|
||||||
@@ -241,14 +243,46 @@ app.controller('ViewingController', function ($scope, $location, $http, bridgeSe
|
|||||||
};
|
};
|
||||||
$scope.testUrl = function (device, type) {
|
$scope.testUrl = function (device, type) {
|
||||||
if(type == "on") {
|
if(type == "on") {
|
||||||
if(device.httpVerb == "PUT" || device.httpVerb == "POST")
|
if(device.httpVerb == "PUT")
|
||||||
$http.put(device.onUrl, device.contentBody);
|
$http.put(device.onUrl, device.contentBody).then(
|
||||||
|
function (response) {
|
||||||
|
$scope.responsedata = response.data;
|
||||||
|
},
|
||||||
|
function (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
else if(device.httpVerb == "POST")
|
||||||
|
$http.post(device.onUrl, device.contentBody).then(
|
||||||
|
function (response) {
|
||||||
|
$scope.responsedata = response.data;
|
||||||
|
},
|
||||||
|
function (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
else
|
else
|
||||||
window.open(device.onUrl, "_blank");
|
window.open(device.onUrl, "_blank");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(device.httpVerb == "PUT" || device.httpVerb == "POST")
|
if(device.httpVerb == "PUT")
|
||||||
$http.put(device.offUrl, device.contentBodyOff);
|
$http.put(device.offUrl, device.contentBodyOff).then(
|
||||||
|
function (response) {
|
||||||
|
$scope.responsedata = response.data;
|
||||||
|
},
|
||||||
|
function (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
else if(device.httpVerb == "POST")
|
||||||
|
$http.post(device.offUrl, device.contentBody).then(
|
||||||
|
function (response) {
|
||||||
|
$scope.responsedata = response.data;
|
||||||
|
},
|
||||||
|
function (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
else
|
else
|
||||||
window.open(device.offUrl, "_blank");
|
window.open(device.offUrl, "_blank");
|
||||||
}
|
}
|
||||||
@@ -335,14 +369,46 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
|
|||||||
|
|
||||||
$scope.testUrl = function (url) {
|
$scope.testUrl = function (url) {
|
||||||
if(type == "on") {
|
if(type == "on") {
|
||||||
if(device.httpVerb == "PUT" || device.httpVerb == "POST")
|
if(device.httpVerb == "PUT")
|
||||||
$http.put(device.onUrl, device.contentBody);
|
$http.put(device.onUrl, device.contentBody).then(
|
||||||
|
function (response) {
|
||||||
|
$scope.responsedata = response.data;
|
||||||
|
},
|
||||||
|
function (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
else if(device.httpVerb == "POST")
|
||||||
|
$http.post(device.onUrl, device.contentBody).then(
|
||||||
|
function (response) {
|
||||||
|
$scope.responsedata = response.data;
|
||||||
|
},
|
||||||
|
function (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
else
|
else
|
||||||
window.open(device.onUrl, "_blank");
|
window.open(device.onUrl, "_blank");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(device.httpVerb == "PUT" || device.httpVerb == "POST")
|
if(device.httpVerb == "PUT")
|
||||||
$http.put(device.offUrl, device.contentBodyOff);
|
$http.put(device.offUrl, device.contentBodyOff).then(
|
||||||
|
function (response) {
|
||||||
|
$scope.responsedata = response.data;
|
||||||
|
},
|
||||||
|
function (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
else if(device.httpVerb == "POST")
|
||||||
|
$http.post(device.offUrl, device.contentBody).then(
|
||||||
|
function (response) {
|
||||||
|
$scope.responsedata = response.data;
|
||||||
|
},
|
||||||
|
function (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
else
|
else
|
||||||
window.open(device.offUrl, "_blank");
|
window.open(device.offUrl, "_blank");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user