mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-19 16:41:53 +00:00
Fix immediate issues for JSON decoding
Fixes #391 Fixes #392 Fixes #398
This commit is contained in:
@@ -6,6 +6,7 @@ public class NamedIP {
|
||||
private String port;
|
||||
private String username;
|
||||
private String password;
|
||||
private Boolean secure;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@@ -37,4 +38,10 @@ public class NamedIP {
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public Boolean getSecure() {
|
||||
return secure;
|
||||
}
|
||||
public void setSecure(Boolean secure) {
|
||||
this.secure = secure;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -524,10 +524,11 @@ public class HueMulator {
|
||||
deviceResponseMap = new HashMap<String, DeviceResponse>();
|
||||
for (DeviceDescriptor device : deviceList) {
|
||||
DeviceResponse deviceResponse = null;
|
||||
if ((device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]))) {
|
||||
HueDeviceIdentifier deviceId = aGsonHandler.fromJson(device.getOnUrl(), HueDeviceIdentifier.class);
|
||||
deviceResponse = myHueHome.getHueDeviceInfo(deviceId, device);
|
||||
}
|
||||
// In the multi command context, this is not valid anymore
|
||||
// if ((device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]))) {
|
||||
// HueDeviceIdentifier deviceId = aGsonHandler.fromJson(device.getOnUrl(), HueDeviceIdentifier.class);
|
||||
// deviceResponse = myHueHome.getHueDeviceInfo(deviceId, device);
|
||||
// }
|
||||
|
||||
if (deviceResponse == null)
|
||||
deviceResponse = DeviceResponse.createResponse(device);
|
||||
@@ -730,7 +731,7 @@ public class HueMulator {
|
||||
}
|
||||
|
||||
// code for backwards compatibility
|
||||
if(!(device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex]))) {
|
||||
if(device.getMapType() != null && device.getMapType().equalsIgnoreCase(DeviceMapTypes.HUE_DEVICE[DeviceMapTypes.typeIndex])) {
|
||||
if(url == null)
|
||||
url = device.getOnUrl();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class CommandHome implements Home {
|
||||
log.debug("Exec Request called with url: " + anItem.getItem().getAsString());
|
||||
String responseString = null;
|
||||
String intermediate;
|
||||
if (anItem.getItem().toString().contains("exec://"))
|
||||
if (anItem.getItem().getAsString().contains("exec://"))
|
||||
intermediate = anItem.getItem().getAsString().substring(anItem.getItem().getAsString().indexOf("://") + 3);
|
||||
else
|
||||
intermediate = anItem.getItem().getAsString();
|
||||
|
||||
@@ -125,9 +125,10 @@ public class HalHome implements Home {
|
||||
|
||||
String anUrl = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(),
|
||||
intensity, targetBri, targetBriInc, false);
|
||||
String aBody;
|
||||
aBody = BrightnessDecode.calculateReplaceIntensityValue(anItem.getHttpBody(),
|
||||
intensity, targetBri, targetBriInc, false);
|
||||
String aBody = null;
|
||||
if(anItem.getHttpBody()!= null && !anItem.getHttpBody().isEmpty())
|
||||
aBody = BrightnessDecode.calculateReplaceIntensityValue(anItem.getHttpBody(),
|
||||
intensity, targetBri, targetBriInc, false);
|
||||
// make call
|
||||
if (anHttpHandler.doHttpRequest(anUrl, anItem.getHttpVerb(), anItem.getContentType(), aBody,
|
||||
new Gson().fromJson(anItem.getHttpHeaders(), NameValue[].class)) == null) {
|
||||
|
||||
@@ -152,7 +152,12 @@ public class HarmonyHome implements Home {
|
||||
myHarmony.startActivity(anActivity);
|
||||
}
|
||||
} else if(anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.HARMONY_BUTTON[DeviceMapTypes.typeIndex])) {
|
||||
String url = anItem.getItem().toString();
|
||||
String url = null;
|
||||
if(anItem.getItem().isJsonObject()) {
|
||||
url = aGsonHandler.toJson(anItem.getItem());
|
||||
} else
|
||||
url = anItem.getItem().getAsString();
|
||||
|
||||
if (url.substring(0, 1).equalsIgnoreCase("{")) {
|
||||
url = "[" + url + "]";
|
||||
}
|
||||
|
||||
@@ -46,9 +46,10 @@ public class HTTPHome implements Home {
|
||||
|
||||
String anUrl = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(),
|
||||
intensity, targetBri, targetBriInc, false);
|
||||
String aBody;
|
||||
aBody = BrightnessDecode.calculateReplaceIntensityValue(anItem.getHttpBody(),
|
||||
intensity, targetBri, targetBriInc, false);
|
||||
String aBody = null;
|
||||
if(anItem.getHttpBody()!= null && !anItem.getHttpBody().isEmpty())
|
||||
aBody = BrightnessDecode.calculateReplaceIntensityValue(anItem.getHttpBody(),
|
||||
intensity, targetBri, targetBriInc, false);
|
||||
// make call
|
||||
if (anHttpHandler.doHttpRequest(anUrl, anItem.getHttpVerb(), anItem.getContentType(), aBody,
|
||||
new Gson().fromJson(anItem.getHttpHeaders(), NameValue[].class)) == null) {
|
||||
|
||||
@@ -80,11 +80,13 @@ public class MQTTHome implements Home {
|
||||
log.debug("executing HUE api request to send message to MQTT broker: " + anItem.getItem().toString());
|
||||
if (validMqtt) {
|
||||
String mqttObject = null;
|
||||
if(anItem.getItem().isJsonObject())
|
||||
mqttObject = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(),
|
||||
intensity, targetBri, targetBriInc, false);
|
||||
if(anItem.getItem().isJsonObject() || anItem.getItem().isJsonArray()) {
|
||||
String theItem = aGsonHandler.toJson(anItem.getItem());
|
||||
mqttObject = BrightnessDecode.calculateReplaceIntensityValue(theItem,
|
||||
intensity, targetBri, targetBriInc, false);
|
||||
}
|
||||
else
|
||||
mqttObject = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().toString(),
|
||||
mqttObject = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(),
|
||||
intensity, targetBri, targetBriInc, false);
|
||||
if (mqttObject.substring(0, 1).equalsIgnoreCase("{"))
|
||||
mqttObject = "[" + mqttObject + "]";
|
||||
|
||||
Reference in New Issue
Block a user