diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index 27f941c..416ef68 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -490,8 +490,12 @@ public class HueMulator implements HueErrorStringSet { return responseString; } - if (request.body().contains("\"bri\"")) - stateHasBri = true; + if (request.body().contains("\"bri\"")) { + if(theStateChanges.isOn() && theStateChanges.getBri() == 0) + stateHasBri = false; + else + stateHasBri = true; + } if (request.body().contains("\"bri_inc\"")) stateHasBriInc = true; @@ -576,8 +580,12 @@ public class HueMulator implements HueErrorStringSet { return responseString; } - if (request.body().contains("\"bri\"")) - stateHasBri = true; + if (request.body().contains("\"bri\"")) { + if(theStateChanges.isOn() && theStateChanges.getBri() == 0) + stateHasBri = false; + else + stateHasBri = true; + } if (request.body().contains("\"bri_inc\"")) stateHasBriInc = true; @@ -1025,19 +1033,30 @@ public class HueMulator implements HueErrorStringSet { return theContent; } - private String doExecRequest(String anItem, int intensity, String lightId) { + private String doExecRequest(String anItem, int intensity, String lightId) { log.debug("Executing request: " + anItem); - String responseString = null; - try { - Process p = Runtime.getRuntime().exec(replaceIntensityValue(anItem, intensity, false)); - log.debug("Process running: " + p.isAlive()); - } catch (IOException e) { - log.warn("Could not execute request: " + anItem, e); - responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling out to device\", \"parameter\": \"/lights/" + lightId + "state\"}}]"; - } - return responseString; - } - + String responseString = null; + if(anItem != null && !anItem.equalsIgnoreCase("")) { + try { + Process p = Runtime.getRuntime().exec(replaceIntensityValue(anItem, intensity, false)); + log.debug("Process running: " + p.isAlive()); + } catch (IOException e) { + log.warn("Could not execute request: " + anItem, e); + responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + + "\",\"description\": \"Error on calling out to device\", \"parameter\": \"/lights/" + lightId + + "state\"}}]"; + } + } + else { + log.warn("Could not execute request. Request is empty."); + responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + + "\",\"description\": \"Error on calling out to device\", \"parameter\": \"/lights/" + lightId + + "state\"}}]"; + } + + return responseString; + } + private String formatSuccessHueResponse(StateChangeBody state, String body, String lightId, DeviceState deviceState) { String responseString = "["; diff --git a/src/main/java/com/bwssystems/HABridge/upnp/UpnpListener.java b/src/main/java/com/bwssystems/HABridge/upnp/UpnpListener.java index 0d4c8d2..14774c9 100644 --- a/src/main/java/com/bwssystems/HABridge/upnp/UpnpListener.java +++ b/src/main/java/com/bwssystems/HABridge/upnp/UpnpListener.java @@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; import com.bwssystems.HABridge.BridgeControlDescriptor; import com.bwssystems.HABridge.BridgeSettingsDescriptor; import com.bwssystems.HABridge.Configuration; +import com.bwssystems.HABridge.api.hue.HuePublicConfig; import java.io.IOException; import java.net.*; @@ -24,6 +25,15 @@ public class UpnpListener { private BridgeControlDescriptor bridgeControl; private boolean discoveryTemplateLatest; private String discoveryTemplate = "HTTP/1.1 200 OK\r\n" + + "HOST: %s:%s" + + "CACHE-CONTROL: max-age=86400\r\n" + + "EXT:\r\n" + + "LOCATION: http://%s:%s/description.xml\r\n" + + "SERVER: FreeRTOS/7.4.2 UPnP/1.0 IpBridge/1.10.0\r\n" + + "hue-bridgeid: %s\r\n" + + "ST: upnp:rootdevice\r\n" + + "USN: uuid:2f402f80-da50-11e1-9b23-001788102201::upnp:rootdevice\r\n\r\n"; + private String discoveryTemplate091516 = "HTTP/1.1 200 OK\r\n" + "CACHE-CONTROL: max-age=86400\r\n" + "EXT:\r\n" + "LOCATION: http://%s:%s/description.xml\r\n" + @@ -33,10 +43,11 @@ public class UpnpListener { private String discoveryTemplateOld = "HTTP/1.1 200 OK\r\n" + "CACHE-CONTROL: max-age=86400\r\n" + "EXT:\r\n" + - "LOCATION: http://%s:%s/description.xml\r\n" + - "SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/0.1\r\n" + + "LOCATION: http://%s:%s/upnp/amazon-ha-bridge/setup.xml\r\n" + + "OPT: \"http://schemas.upnp.org/upnp/1/0/\"; ns=01\r\n" + + "01-NLS: %s\r\n" + "ST: urn:schemas-upnp-org:device:basic:1\r\n" + - "USN: uuid:Socket-1_0-221438K0100073::urn:schemas-upnp-org:device:basic:1\r\n\r\n"; + "USN: uuid:Socket-1_0-221438K0100073::urn:Belkin:device:**\r\n\r\n"; public UpnpListener(BridgeSettingsDescriptor theSettings, BridgeControlDescriptor theControl) { super(); @@ -208,9 +219,9 @@ public class UpnpListener { protected void sendUpnpResponse(DatagramSocket socket, InetAddress requester, int sourcePort) throws IOException { String discoveryResponse = null; if(discoveryTemplateLatest) - discoveryResponse = String.format(discoveryTemplate, responseAddress, httpServerPort); + discoveryResponse = String.format(discoveryTemplate, Configuration.UPNP_MULTICAST_ADDRESS, Configuration.UPNP_DISCOVERY_PORT, responseAddress, httpServerPort, HuePublicConfig.createConfig("temp", responseAddress).getBridgeid()); else - discoveryResponse = String.format(discoveryTemplateOld, Configuration.UPNP_MULTICAST_ADDRESS, Configuration.UPNP_DISCOVERY_PORT, responseAddress, httpServerPort); + discoveryResponse = String.format(discoveryTemplate091516, responseAddress, httpServerPort); if(traceupnp) log.info("Traceupnp: sendUpnpResponse discovery template with address: " + responseAddress + " and port: " + httpServerPort); else