mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-19 16:41:53 +00:00
Updated upnp response to be closer to the hue bridge v2 spec. Updated
handling for is on when bri is 0. Updated exec to check for empty call.
This commit is contained in:
@@ -490,8 +490,12 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
return responseString;
|
return responseString;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.body().contains("\"bri\""))
|
if (request.body().contains("\"bri\"")) {
|
||||||
stateHasBri = true;
|
if(theStateChanges.isOn() && theStateChanges.getBri() == 0)
|
||||||
|
stateHasBri = false;
|
||||||
|
else
|
||||||
|
stateHasBri = true;
|
||||||
|
}
|
||||||
if (request.body().contains("\"bri_inc\""))
|
if (request.body().contains("\"bri_inc\""))
|
||||||
stateHasBriInc = true;
|
stateHasBriInc = true;
|
||||||
|
|
||||||
@@ -576,8 +580,12 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
return responseString;
|
return responseString;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.body().contains("\"bri\""))
|
if (request.body().contains("\"bri\"")) {
|
||||||
stateHasBri = true;
|
if(theStateChanges.isOn() && theStateChanges.getBri() == 0)
|
||||||
|
stateHasBri = false;
|
||||||
|
else
|
||||||
|
stateHasBri = true;
|
||||||
|
}
|
||||||
if (request.body().contains("\"bri_inc\""))
|
if (request.body().contains("\"bri_inc\""))
|
||||||
stateHasBriInc = true;
|
stateHasBriInc = true;
|
||||||
|
|
||||||
@@ -1025,18 +1033,29 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
return theContent;
|
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);
|
log.debug("Executing request: " + anItem);
|
||||||
String responseString = null;
|
String responseString = null;
|
||||||
try {
|
if(anItem != null && !anItem.equalsIgnoreCase("")) {
|
||||||
Process p = Runtime.getRuntime().exec(replaceIntensityValue(anItem, intensity, false));
|
try {
|
||||||
log.debug("Process running: " + p.isAlive());
|
Process p = Runtime.getRuntime().exec(replaceIntensityValue(anItem, intensity, false));
|
||||||
} catch (IOException e) {
|
log.debug("Process running: " + p.isAlive());
|
||||||
log.warn("Could not execute request: " + anItem, e);
|
} catch (IOException e) {
|
||||||
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId + "\",\"description\": \"Error on calling out to device\", \"parameter\": \"/lights/" + lightId + "state\"}}]";
|
log.warn("Could not execute request: " + anItem, e);
|
||||||
}
|
responseString = "[{\"error\":{\"type\": 6, \"address\": \"/lights/" + lightId
|
||||||
return responseString;
|
+ "\",\"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) {
|
private String formatSuccessHueResponse(StateChangeBody state, String body, String lightId, DeviceState deviceState) {
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import com.bwssystems.HABridge.BridgeControlDescriptor;
|
import com.bwssystems.HABridge.BridgeControlDescriptor;
|
||||||
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
import com.bwssystems.HABridge.BridgeSettingsDescriptor;
|
||||||
import com.bwssystems.HABridge.Configuration;
|
import com.bwssystems.HABridge.Configuration;
|
||||||
|
import com.bwssystems.HABridge.api.hue.HuePublicConfig;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
@@ -24,6 +25,15 @@ public class UpnpListener {
|
|||||||
private BridgeControlDescriptor bridgeControl;
|
private BridgeControlDescriptor bridgeControl;
|
||||||
private boolean discoveryTemplateLatest;
|
private boolean discoveryTemplateLatest;
|
||||||
private String discoveryTemplate = "HTTP/1.1 200 OK\r\n" +
|
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" +
|
"CACHE-CONTROL: max-age=86400\r\n" +
|
||||||
"EXT:\r\n" +
|
"EXT:\r\n" +
|
||||||
"LOCATION: http://%s:%s/description.xml\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" +
|
private String discoveryTemplateOld = "HTTP/1.1 200 OK\r\n" +
|
||||||
"CACHE-CONTROL: max-age=86400\r\n" +
|
"CACHE-CONTROL: max-age=86400\r\n" +
|
||||||
"EXT:\r\n" +
|
"EXT:\r\n" +
|
||||||
"LOCATION: http://%s:%s/description.xml\r\n" +
|
"LOCATION: http://%s:%s/upnp/amazon-ha-bridge/setup.xml\r\n" +
|
||||||
"SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/0.1\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" +
|
"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) {
|
public UpnpListener(BridgeSettingsDescriptor theSettings, BridgeControlDescriptor theControl) {
|
||||||
super();
|
super();
|
||||||
@@ -208,9 +219,9 @@ public class UpnpListener {
|
|||||||
protected void sendUpnpResponse(DatagramSocket socket, InetAddress requester, int sourcePort) throws IOException {
|
protected void sendUpnpResponse(DatagramSocket socket, InetAddress requester, int sourcePort) throws IOException {
|
||||||
String discoveryResponse = null;
|
String discoveryResponse = null;
|
||||||
if(discoveryTemplateLatest)
|
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
|
else
|
||||||
discoveryResponse = String.format(discoveryTemplateOld, Configuration.UPNP_MULTICAST_ADDRESS, Configuration.UPNP_DISCOVERY_PORT, responseAddress, httpServerPort);
|
discoveryResponse = String.format(discoveryTemplate091516, responseAddress, httpServerPort);
|
||||||
if(traceupnp)
|
if(traceupnp)
|
||||||
log.info("Traceupnp: sendUpnpResponse discovery template with address: " + responseAddress + " and port: " + httpServerPort);
|
log.info("Traceupnp: sendUpnpResponse discovery template with address: " + responseAddress + " and port: " + httpServerPort);
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user