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,46 +111,54 @@ 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 (thermoSetting.getControl().equalsIgnoreCase("temp")) { if(anItem.getItem().isJsonObject())
if (targetBri != null) { thermoSetting = aGsonHandler.fromJson(anItem.getItem(), NestInstruction.class);
if (isFarenheit) else
thermoSetting thermoSetting = aGsonHandler.fromJson(anItem.getItem().getAsString(), NestInstruction.class);
.setTemp( if (thermoSetting.getControl().equalsIgnoreCase("temp")) {
String.valueOf((Double if (targetBri != null) {
.parseDouble(BrightnessDecode.calculateReplaceIntensityValue(thermoSetting.getTemp(), if (isFarenheit)
intensity, targetBri, targetBriInc, false)) - 32.0) / 1.8)); thermoSetting
else .setTemp(
thermoSetting String.valueOf((Double
.setTemp( .parseDouble(BrightnessDecode.calculateReplaceIntensityValue(thermoSetting.getTemp(),
String.valueOf(Double.parseDouble(BrightnessDecode.calculateReplaceIntensityValue(thermoSetting.getTemp(), intensity, targetBri, targetBriInc, false)) - 32.0) / 1.8));
intensity, targetBri, targetBriInc, false)))); else
log.debug("Setting thermostat: " + thermoSetting.getName() + " to " thermoSetting
+ thermoSetting.getTemp() + "C"); .setTemp(
theNest.getThermostat(thermoSetting.getName()) String.valueOf(Double.parseDouble(BrightnessDecode.calculateReplaceIntensityValue(thermoSetting.getTemp(),
.setTargetTemperature(Float.parseFloat(thermoSetting.getTemp())); intensity, targetBri, targetBriInc, false))));
} log.debug("Setting thermostat: " + thermoSetting.getName() + " to "
} else if (thermoSetting.getControl().contains("range") + thermoSetting.getTemp() + "C");
|| thermoSetting.getControl().contains("heat")
|| thermoSetting.getControl().contains("cool")
|| thermoSetting.getControl().contains("off")) {
log.debug("Setting thermostat target type: " + thermoSetting.getName() + " to "
+ thermoSetting.getControl());
theNest.getThermostat(thermoSetting.getName()).setTargetType(thermoSetting.getControl());
} else if (thermoSetting.getControl().contains("fan")) {
log.debug("Setting thermostat fan mode: " + thermoSetting.getName() + " to "
+ thermoSetting.getControl().substring(4));
theNest.getThermostat(thermoSetting.getName()) theNest.getThermostat(thermoSetting.getName())
.setFanMode(thermoSetting.getControl().substring(4)); .setTargetTemperature(Float.parseFloat(thermoSetting.getTemp()));
} else {
log.warn("no valid Nest control info: " + thermoSetting.getControl());
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
+ "\",\"description\": \"no valid Nest control info\", \"parameter\": \"/lights/"
+ lightId + "state\"}}]";
} }
} else if (thermoSetting.getControl().contains("range")
|| thermoSetting.getControl().contains("heat")
|| thermoSetting.getControl().contains("cool")
|| thermoSetting.getControl().contains("off")) {
log.debug("Setting thermostat target type: " + thermoSetting.getName() + " to "
+ thermoSetting.getControl());
theNest.getThermostat(thermoSetting.getName()).setTargetType(thermoSetting.getControl());
} else if (thermoSetting.getControl().contains("fan")) {
log.debug("Setting thermostat fan mode: " + thermoSetting.getName() + " to "
+ thermoSetting.getControl().substring(4));
theNest.getThermostat(thermoSetting.getName())
.setFanMode(thermoSetting.getControl().substring(4));
} else {
log.warn("no valid Nest control info: " + thermoSetting.getControl());
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
+ "\",\"description\": \"no valid Nest control info\", \"parameter\": \"/lights/"
+ lightId + "state\"}}]";
}
} }
return responseString; return responseString;
} }

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,9 +125,13 @@ 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());
if (homeAssistant == null) { if (homeAssistant == null) {
log.warn("Should not get here, no HomeAssistants available"); log.warn("Should not get here, no HomeAssistants available");

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,8 +79,13 @@ 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); intensity, targetBri, targetBriInc, false);
else
mqttObject = BrightnessDecode.calculateReplaceIntensityValue(anItem.getItem().toString(),
intensity, targetBri, targetBriInc, false);
if (mqttObject.substring(0, 1).equalsIgnoreCase("{")) if (mqttObject.substring(0, 1).equalsIgnoreCase("{"))
mqttObject = "[" + mqttObject + "]"; mqttObject = "[" + mqttObject + "]";
MQTTMessage[] mqttMessages = aGsonHandler.fromJson(mqttObject, MQTTMessage[].class); MQTTMessage[] mqttMessages = aGsonHandler.fromJson(mqttObject, MQTTMessage[].class);