mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 16:17:30 +00:00
Updating hue emulation repsonses using hue android app. fixed issues in
returning the hue config and for requesting the mac address.
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>com.bwssystems.HABridge</groupId>
|
||||
<artifactId>ha-bridge</artifactId>
|
||||
<version>1.2.2</version>
|
||||
<version>1.2.2a</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HA Bridge</name>
|
||||
|
||||
@@ -84,6 +84,10 @@ public class HueConfig
|
||||
|
||||
sb.append("00:00:88:00:bb:ee");
|
||||
|
||||
} catch (Exception e){
|
||||
|
||||
sb.append("00:00:88:00:bb:ee");
|
||||
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
||||
@@ -117,7 +117,7 @@ public class HueMulator {
|
||||
String aDeviceType = null;
|
||||
|
||||
if(bridgeSettings.isTraceupnp())
|
||||
log.info("Traceupnp: hue api user create requested: " + request.body() + " from " + request.ip());
|
||||
log.info("Traceupnp: hue api/ user create requested: " + request.body() + " from " + request.ip());
|
||||
log.debug("hue api user create requested: " + request.body() + " from " + request.ip());
|
||||
|
||||
if(request.body() != null && !request.body().isEmpty()) {
|
||||
@@ -155,7 +155,8 @@ public class HueMulator {
|
||||
String newUser = null;
|
||||
String aDeviceType = null;
|
||||
|
||||
log.info("HH trace: hue api user create requested: " + request.body() + " from " + request.ip());
|
||||
if(bridgeSettings.isTraceupnp())
|
||||
log.info("Traceupnp: hue api/* user create requested: " + request.body() + " from " + request.ip());
|
||||
|
||||
if(request.body() != null && !request.body().isEmpty()) {
|
||||
aNewUser = new Gson().fromJson(request.body(), UserCreateRequest.class);
|
||||
@@ -177,22 +178,26 @@ public class HueMulator {
|
||||
|
||||
// http://ip_address:port/api/config returns json objects for the config when no user is given
|
||||
get(HUE_CONTEXT + "/config", "application/json", (request, response) -> {
|
||||
String userId = request.params(":userid");
|
||||
log.debug("hue api config requested: " + userId + " from " + request.ip());
|
||||
HueApiResponse apiResponse = new HueApiResponse("Philips hue", request.ip(), "My App", userId);
|
||||
if(bridgeSettings.isTraceupnp())
|
||||
log.info("Traceupnp: hue api/config config requested: <no_user> from " + request.ip());
|
||||
log.debug("hue api config requested: <no_user> from " + request.ip());
|
||||
HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(), "My App", "none");
|
||||
|
||||
response.type("application/json; charset=utf-8");
|
||||
response.status(HttpStatus.SC_OK);
|
||||
String responseString = null;
|
||||
responseString = "[{\"swversion\":\"" + apiResponse.getConfig().getSwversion() + "\",\"apiversion\":\"" + apiResponse.getConfig().getApiversion() + "\",\"name\":\"" + apiResponse.getConfig().getName() + "\",\"mac\":\"" + apiResponse.getConfig().getMac() + "\"}]";
|
||||
return responseString;
|
||||
});
|
||||
// String responseString = null;
|
||||
// responseString = "[{\"swversion\":\"" + apiResponse.getConfig().getSwversion() + "\",\"apiversion\":\"" + apiResponse.getConfig().getApiversion() + "\",\"name\":\"" + apiResponse.getConfig().getName() + "\",\"mac\":\"" + apiResponse.getConfig().getMac() + "\"}]";
|
||||
// return responseString;
|
||||
return apiResponse.getConfig();
|
||||
}, new JsonTransformer());
|
||||
|
||||
// http://ip_address:port/api/{userId}/config returns json objects for the config
|
||||
get(HUE_CONTEXT + "/:userid/config", "application/json", (request, response) -> {
|
||||
String userId = request.params(":userid");
|
||||
if(bridgeSettings.isTraceupnp())
|
||||
log.info("Traceupnp: hue api/:userid/config config requested: " + userId + " from " + request.ip());
|
||||
log.debug("hue api config requested: " + userId + " from " + request.ip());
|
||||
HueApiResponse apiResponse = new HueApiResponse("Philips hue", request.ip(), "My App", userId);
|
||||
HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(), "My App", userId);
|
||||
|
||||
response.type("application/json; charset=utf-8");
|
||||
response.status(HttpStatus.SC_OK);
|
||||
@@ -216,7 +221,7 @@ public class HueMulator {
|
||||
deviceList.put(descriptor.getId(), deviceResponse);
|
||||
}
|
||||
);
|
||||
HueApiResponse apiResponse = new HueApiResponse("Philips hue", request.ip(), "My App", userId);
|
||||
HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(), "My App", userId);
|
||||
apiResponse.setLights(deviceList);
|
||||
|
||||
response.type("application/json; charset=utf-8");
|
||||
|
||||
@@ -96,30 +96,33 @@ public class UpnpListener {
|
||||
//Only respond to discover request for strict upnp form
|
||||
String packetString = new String(packet.getData());
|
||||
if(packetString != null && packetString.startsWith("M-SEARCH * HTTP/1.1") && packetString.contains("\"ssdp:discover\"")){
|
||||
if(traceupnp) {
|
||||
log.info("Traceupnp: SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + ", body: " + packetString);
|
||||
log.info("Traceupnp: isSSDPDiscovery found message to be an M-SEARCH message.");
|
||||
}
|
||||
else {
|
||||
log.debug("Got SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + ", body: " + packetString);
|
||||
log.debug("Found message to be an M-SEARCH message.");
|
||||
}
|
||||
log.debug("isSSDPDiscovery Found message to be an M-SEARCH message.");
|
||||
log.debug("isSSDPDiscovery Got SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + ", body: " + packetString);
|
||||
|
||||
if(strict && (packetString.contains("ST: urn:schemas-upnp-org:device:basic:1") || packetString.contains("ST: upnp:rootdevice") || packetString.contains("ST: ssdp:all")))
|
||||
{
|
||||
if(traceupnp)
|
||||
if(traceupnp) {
|
||||
log.info("Traceupnp: isSSDPDiscovery found message to be an M-SEARCH message.");
|
||||
log.info("Traceupnp: isSSDPDiscovery found message to be valid under strict rules - strict: " + strict);
|
||||
log.info("Traceupnp: SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + ", body: " + packetString);
|
||||
}
|
||||
log.debug("isSSDPDiscovery found message to be valid under strict rules - strict: " + strict);
|
||||
return true;
|
||||
}
|
||||
else if (!strict)
|
||||
{
|
||||
if(traceupnp)
|
||||
if(traceupnp) {
|
||||
log.info("Traceupnp: isSSDPDiscovery found message to be an M-SEARCH message.");
|
||||
log.info("Traceupnp: isSSDPDiscovery found message to be valid under loose rules - strict: " + strict);
|
||||
log.info("Traceupnp: SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + ", body: " + packetString);
|
||||
}
|
||||
log.debug("isSSDPDiscovery found message to be valid under loose rules - strict: " + strict);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(traceupnp)
|
||||
log.info("Traceupnp: isSSDPDiscovery found message to not be valid - strict: " + strict);
|
||||
log.debug("isSSDPDiscovery found message to be an M-SEARCH message.");
|
||||
log.debug("isSSDPDiscovery found message to not be valid - strict: " + strict);
|
||||
log.debug("SSDP packet from " + packet.getAddress().getHostAddress() + ":" + packet.getPort() + ", body: " + packetString);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user