Updated bridge to be robust on put/post calls and testing. HAd to add a

body for off types.
This commit is contained in:
Admin
2015-10-02 16:35:17 -05:00
parent 2789d8c180
commit 7514e36edb
12 changed files with 142 additions and 40 deletions

View File

@@ -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;
}
}

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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);