Fixed more immediate issues

Fixes #272
Fixes #384
Fixes #387
Fixes #389
This commit is contained in:
Admin
2017-01-24 09:31:48 -06:00
parent 58e1679529
commit fd486588f5
8 changed files with 68 additions and 47 deletions

View File

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

View File

@@ -26,7 +26,7 @@ public class BrightnessDecode {
} else if (targetBriInc != null) { } else if (targetBriInc != null) {
if ((setIntensity + targetBriInc) <= 0) if ((setIntensity + targetBriInc) <= 0)
setIntensity = targetBriInc; setIntensity = targetBriInc;
else if ((setIntensity + targetBriInc) > 255) else if ((setIntensity + targetBriInc) > 254)
setIntensity = targetBriInc; setIntensity = targetBriInc;
else else
setIntensity = setIntensity + targetBriInc; setIntensity = setIntensity + targetBriInc;
@@ -38,7 +38,7 @@ public class BrightnessDecode {
* light weight templating here, was going to use free marker but it was a * light weight templating here, was going to use free marker but it was a
* bit too heavy for what we were trying to do. * bit too heavy for what we were trying to do.
* *
* currently provides: intensity.byte : 0-255 brightness. this is raw from * currently provides: intensity.byte : 0-254 brightness. this is raw from
* the echo intensity.percent : 0-100, adjusted for the vera * the echo intensity.percent : 0-100, adjusted for the vera
* intensity.math(X*1) : where X is the value from the interface call and * intensity.math(X*1) : where X is the value from the interface call and
* can use net.java.dev.eval math * can use net.java.dev.eval math

View File

@@ -276,7 +276,7 @@ public class HueMulator {
} }
if (deviceState != null) { if (deviceState != null) {
deviceState.setOn(stateChanges.isOn()); deviceState.setOn(stateChanges.isOn());
if(!deviceState.isOn() && deviceState.getBri() == 255) if(!deviceState.isOn() && deviceState.getBri() == 254)
deviceState.setBri(0); deviceState.setBri(0);
} }
notFirstChange = true; notFirstChange = true;
@@ -416,7 +416,7 @@ public class HueMulator {
} }
if(deviceState.isOn() && deviceState.getBri() <= 0) if(deviceState.isOn() && deviceState.getBri() <= 0)
deviceState.setBri(255); deviceState.setBri(254);
if(!deviceState.isOn() && (targetBri != null || targetBriInc != null)) if(!deviceState.isOn() && (targetBri != null || targetBriInc != null))
deviceState.setOn(true); deviceState.setOn(true);
@@ -734,7 +734,7 @@ public class HueMulator {
if(url == null) if(url == null)
url = device.getOnUrl(); url = device.getOnUrl();
} }
if (url != null) { if (url != null && !url.equals("")) {
if (!url.startsWith("[")) { if (!url.startsWith("[")) {
if (url.startsWith("{\"item")) if (url.startsWith("{\"item"))
url = "[" + url + "]"; url = "[" + url + "]";

View File

@@ -111,10 +111,18 @@ public class NestHome implements com.bwssystems.HABridge.Home {
+ "\",\"description\": \"Should not get here, no Nest available\", \"parameter\": \"/lights/" + "\",\"description\": \"Should not get here, no Nest available\", \"parameter\": \"/lights/"
+ lightId + "state\"}}]"; + lightId + "state\"}}]";
} else if (anItem.getType() != null && anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.NEST_HOMEAWAY[DeviceMapTypes.typeIndex])) { } else if (anItem.getType() != null && anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.NEST_HOMEAWAY[DeviceMapTypes.typeIndex])) {
NestInstruction homeAway = aGsonHandler.fromJson(anItem.getItem().toString(), NestInstruction.class); NestInstruction homeAway = null;
if(anItem.getItem().isJsonObject())
homeAway = aGsonHandler.fromJson(anItem.getItem(), NestInstruction.class);
else
homeAway = aGsonHandler.fromJson(anItem.getItem().getAsString(), NestInstruction.class);
theNest.getHome(homeAway.getName()).setAway(homeAway.getAway()); theNest.getHome(homeAway.getName()).setAway(homeAway.getAway());
} else if (anItem.getType() != null && anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.NEST_THERMO_SET[DeviceMapTypes.typeIndex])) { } else if (anItem.getType() != null && anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.NEST_THERMO_SET[DeviceMapTypes.typeIndex])) {
NestInstruction thermoSetting = aGsonHandler.fromJson(anItem.getItem().toString(), NestInstruction.class); NestInstruction thermoSetting = null;
if(anItem.getItem().isJsonObject())
thermoSetting = aGsonHandler.fromJson(anItem.getItem(), NestInstruction.class);
else
thermoSetting = aGsonHandler.fromJson(anItem.getItem().getAsString(), NestInstruction.class);
if (thermoSetting.getControl().equalsIgnoreCase("temp")) { if (thermoSetting.getControl().equalsIgnoreCase("temp")) {
if (targetBri != null) { if (targetBri != null) {
if (isFarenheit) if (isFarenheit)

View File

@@ -26,7 +26,7 @@ public class CommandHome implements Home {
String responseString = null; String responseString = null;
String intermediate; String intermediate;
if (anItem.getItem().toString().contains("exec://")) if (anItem.getItem().toString().contains("exec://"))
intermediate = anItem.getItem().getAsString().substring(anItem.getItem().toString().indexOf("://") + 3); intermediate = anItem.getItem().getAsString().substring(anItem.getItem().getAsString().indexOf("://") + 3);
else else
intermediate = anItem.getItem().getAsString(); intermediate = anItem.getItem().getAsString();
String anError = doExecRequest(intermediate, String anError = doExecRequest(intermediate,

View File

@@ -125,7 +125,11 @@ public class HassHome implements Home {
+ lightId + "state\"}}]"; + lightId + "state\"}}]";
} else { } else {
HassCommand hassCommand = aGsonHandler.fromJson(anItem.getItem(), HassCommand.class); HassCommand hassCommand = null;
if(anItem.getItem().isJsonObject())
hassCommand = aGsonHandler.fromJson(anItem.getItem(), HassCommand.class);
else
hassCommand = aGsonHandler.fromJson(anItem.getItem().getAsString(), HassCommand.class);
hassCommand.setBri(BrightnessDecode.replaceIntensityValue(hassCommand.getBri(), hassCommand.setBri(BrightnessDecode.replaceIntensityValue(hassCommand.getBri(),
BrightnessDecode.calculateIntensity(intensity, targetBri, targetBriInc), false)); BrightnessDecode.calculateIntensity(intensity, targetBri, targetBriInc), false));
HomeAssistant homeAssistant = getHomeAssistant(hassCommand.getHassName()); HomeAssistant homeAssistant = getHomeAssistant(hassCommand.getHassName());

View File

@@ -80,7 +80,11 @@ public class HueHome implements Home {
if(!validHue) if(!validHue)
return null; return null;
String responseString = null; String responseString = null;
HueDeviceIdentifier deviceId = aGsonHandler.fromJson(anItem.getItem(), HueDeviceIdentifier.class); HueDeviceIdentifier deviceId = null;
if(anItem.getItem().isJsonObject())
deviceId = aGsonHandler.fromJson(anItem.getItem(), HueDeviceIdentifier.class);
else
deviceId = aGsonHandler.fromJson(anItem.getItem().getAsString(), HueDeviceIdentifier.class);
if(deviceId.getHueName() == null || deviceId.getHueName().isEmpty()) if(deviceId.getHueName() == null || deviceId.getHueName().isEmpty())
deviceId.setHueName(device.getTargetDevice()); deviceId.setHueName(device.getTargetDevice());

View File

@@ -79,7 +79,12 @@ public class MQTTHome implements Home {
String responseString = null; String responseString = null;
log.debug("executing HUE api request to send message to MQTT broker: " + anItem.getItem().toString()); log.debug("executing HUE api request to send message to MQTT broker: " + anItem.getItem().toString());
if (validMqtt) { if (validMqtt) {
String mqttObject = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().toString(), String mqttObject = null;
if(anItem.getItem().isJsonObject())
mqttObject = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().getAsString(),
intensity, targetBri, targetBriInc, false);
else
mqttObject = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().toString(),
intensity, targetBri, targetBriInc, false); intensity, targetBri, targetBriInc, false);
if (mqttObject.substring(0, 1).equalsIgnoreCase("{")) if (mqttObject.substring(0, 1).equalsIgnoreCase("{"))
mqttObject = "[" + mqttObject + "]"; mqttObject = "[" + mqttObject + "]";