diff --git a/pom.xml b/pom.xml index c8d90b4..59ffd55 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 4.0.1 + 4.0.2 jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java b/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java index 0c26dfd..55da9dd 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java +++ b/src/main/java/com/bwssystems/HABridge/hue/BrightnessDecode.java @@ -26,7 +26,7 @@ public class BrightnessDecode { } else if (targetBriInc != null) { if ((setIntensity + targetBriInc) <= 0) setIntensity = targetBriInc; - else if ((setIntensity + targetBriInc) > 255) + else if ((setIntensity + targetBriInc) > 254) setIntensity = targetBriInc; else setIntensity = setIntensity + targetBriInc; @@ -38,7 +38,7 @@ public class BrightnessDecode { * light weight templating here, was going to use free marker but it was a * 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 * intensity.math(X*1) : where X is the value from the interface call and * can use net.java.dev.eval math diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index 87829fc..4618abb 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -276,7 +276,7 @@ public class HueMulator { } if (deviceState != null) { deviceState.setOn(stateChanges.isOn()); - if(!deviceState.isOn() && deviceState.getBri() == 255) + if(!deviceState.isOn() && deviceState.getBri() == 254) deviceState.setBri(0); } notFirstChange = true; @@ -416,7 +416,7 @@ public class HueMulator { } if(deviceState.isOn() && deviceState.getBri() <= 0) - deviceState.setBri(255); + deviceState.setBri(254); if(!deviceState.isOn() && (targetBri != null || targetBriInc != null)) deviceState.setOn(true); @@ -734,7 +734,7 @@ public class HueMulator { if(url == null) url = device.getOnUrl(); } - if (url != null) { + if (url != null && !url.equals("")) { if (!url.startsWith("[")) { if (url.startsWith("{\"item")) url = "[" + url + "]"; diff --git a/src/main/java/com/bwssystems/HABridge/plugins/NestBridge/NestHome.java b/src/main/java/com/bwssystems/HABridge/plugins/NestBridge/NestHome.java index 8af25a3..3e4bc9d 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/NestBridge/NestHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/NestBridge/NestHome.java @@ -111,46 +111,54 @@ public class NestHome implements com.bwssystems.HABridge.Home { + "\",\"description\": \"Should not get here, no Nest available\", \"parameter\": \"/lights/" + lightId + "state\"}}]"; } 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()); } else if (anItem.getType() != null && anItem.getType().trim().equalsIgnoreCase(DeviceMapTypes.NEST_THERMO_SET[DeviceMapTypes.typeIndex])) { - NestInstruction thermoSetting = aGsonHandler.fromJson(anItem.getItem().toString(), NestInstruction.class); - if (thermoSetting.getControl().equalsIgnoreCase("temp")) { - if (targetBri != null) { - if (isFarenheit) - thermoSetting - .setTemp( - String.valueOf((Double - .parseDouble(BrightnessDecode.calculateReplaceIntensityValue(thermoSetting.getTemp(), - intensity, targetBri, targetBriInc, false)) - 32.0) / 1.8)); - else - thermoSetting - .setTemp( - String.valueOf(Double.parseDouble(BrightnessDecode.calculateReplaceIntensityValue(thermoSetting.getTemp(), - intensity, targetBri, targetBriInc, false)))); - log.debug("Setting thermostat: " + thermoSetting.getName() + " to " - + thermoSetting.getTemp() + "C"); - theNest.getThermostat(thermoSetting.getName()) - .setTargetTemperature(Float.parseFloat(thermoSetting.getTemp())); - } - } 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)); + 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 (targetBri != null) { + if (isFarenheit) + thermoSetting + .setTemp( + String.valueOf((Double + .parseDouble(BrightnessDecode.calculateReplaceIntensityValue(thermoSetting.getTemp(), + intensity, targetBri, targetBriInc, false)) - 32.0) / 1.8)); + else + thermoSetting + .setTemp( + String.valueOf(Double.parseDouble(BrightnessDecode.calculateReplaceIntensityValue(thermoSetting.getTemp(), + intensity, targetBri, targetBriInc, false)))); + log.debug("Setting thermostat: " + thermoSetting.getName() + " to " + + thermoSetting.getTemp() + "C"); 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\"}}]"; + .setTargetTemperature(Float.parseFloat(thermoSetting.getTemp())); } + } 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; } diff --git a/src/main/java/com/bwssystems/HABridge/plugins/exec/CommandHome.java b/src/main/java/com/bwssystems/HABridge/plugins/exec/CommandHome.java index 71ef5f0..f87c48b 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/exec/CommandHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/exec/CommandHome.java @@ -26,7 +26,7 @@ public class CommandHome implements Home { String responseString = null; String intermediate; 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 intermediate = anItem.getItem().getAsString(); String anError = doExecRequest(intermediate, diff --git a/src/main/java/com/bwssystems/HABridge/plugins/hass/HassHome.java b/src/main/java/com/bwssystems/HABridge/plugins/hass/HassHome.java index fd8df64..fd73f33 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/hass/HassHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/hass/HassHome.java @@ -125,9 +125,13 @@ public class HassHome implements Home { + lightId + "state\"}}]"; } 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(), - BrightnessDecode.calculateIntensity(intensity, targetBri, targetBriInc), false)); + BrightnessDecode.calculateIntensity(intensity, targetBri, targetBriInc), false)); HomeAssistant homeAssistant = getHomeAssistant(hassCommand.getHassName()); if (homeAssistant == null) { log.warn("Should not get here, no HomeAssistants available"); diff --git a/src/main/java/com/bwssystems/HABridge/plugins/hue/HueHome.java b/src/main/java/com/bwssystems/HABridge/plugins/hue/HueHome.java index 3bfcf5c..e0c5b76 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/hue/HueHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/hue/HueHome.java @@ -80,7 +80,11 @@ public class HueHome implements Home { if(!validHue) return 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()) deviceId.setHueName(device.getTargetDevice()); diff --git a/src/main/java/com/bwssystems/HABridge/plugins/mqtt/MQTTHome.java b/src/main/java/com/bwssystems/HABridge/plugins/mqtt/MQTTHome.java index c544762..4716199 100644 --- a/src/main/java/com/bwssystems/HABridge/plugins/mqtt/MQTTHome.java +++ b/src/main/java/com/bwssystems/HABridge/plugins/mqtt/MQTTHome.java @@ -79,8 +79,13 @@ public class MQTTHome implements Home { String responseString = null; log.debug("executing HUE api request to send message to MQTT broker: " + anItem.getItem().toString()); 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); if (mqttObject.substring(0, 1).equalsIgnoreCase("{")) mqttObject = "[" + mqttObject + "]"; MQTTMessage[] mqttMessages = aGsonHandler.fromJson(mqttObject, MQTTMessage[].class);