Updatting upnp responses

This commit is contained in:
Admin
2016-09-26 17:03:30 -05:00
parent faa67827c6
commit 4da5f65d89
6 changed files with 44 additions and 36 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>3.1.0a</version>
<version>3.1.0b</version>
<packaging>jar</packaging>
<name>HA Bridge</name>

View File

@@ -17,7 +17,7 @@ public class DeviceState {
private String colormode;
private boolean reachable;
private List<Double> xy;
private int transitiontime;
// private int transitiontime;
public boolean isOn() {
return on;
@@ -98,13 +98,13 @@ public class DeviceState {
public void setXy(List<Double> xy) {
this.xy = xy;
}
public int getTransitiontime() {
return transitiontime;
}
// public int getTransitiontime() {
// return transitiontime;
// }
public void setTransitiontime(int transitiontime) {
this.transitiontime = transitiontime;
}
// public void setTransitiontime(int transitiontime) {
// this.transitiontime = transitiontime;
// }
public static DeviceState createDeviceState() {
DeviceState newDeviceState = new DeviceState();

View File

@@ -1,5 +1,10 @@
package com.bwssystems.HABridge.api.hue;
import java.util.List;
import com.bwssystems.HABridge.dao.DeviceDescriptor;
import com.bwssystems.HABridge.dao.DeviceRepository;
public class GroupResponse {
private DeviceState action;
private String[] lights;
@@ -23,11 +28,17 @@ public class GroupResponse {
this.name = name;
}
public static GroupResponse createGroupResponse(String[] theLights) {
public static GroupResponse createGroupResponse(List<DeviceDescriptor> deviceList) {
String[] theList = new String[deviceList.size()];
int i = 0;
for (DeviceDescriptor device : deviceList) {
theList[i] = device.getId();
i++;
}
GroupResponse theResponse = new GroupResponse();
theResponse.setAction(DeviceState.createDeviceState());
theResponse.setName("Lightset 0");
theResponse.setLights(theLights);
theResponse.setLights(theList);
return theResponse;
}
}

View File

@@ -71,18 +71,18 @@ public class HuePublicConfig
{
StringTokenizer st = new StringTokenizer(macAddr, ":");
String bridgeId = "";
String port = null;
// String port = null;
while(st.hasMoreTokens()) {
bridgeId = bridgeId + st.nextToken();
}
if(ipAddr.contains(":")) {
port = ipAddr.substring(ipAddr.indexOf(":"));
BigInteger bigInt = BigInteger.valueOf(Integer.getInteger(port).intValue());
byte[] theBytes = bigInt.toByteArray();
bridgeId = bridgeId + DatatypeConverter.printHexBinary(theBytes);
}
else
bridgeId = bridgeId + "0800";
// if(ipAddr.contains(":")) {
// port = ipAddr.substring(ipAddr.indexOf(":"));
// BigInteger bigInt = BigInteger.valueOf(Integer.getInteger(port).intValue());
// byte[] theBytes = bigInt.toByteArray();
// bridgeId = bridgeId + DatatypeConverter.printHexBinary(theBytes);
// }
// else
// bridgeId = bridgeId + "0800";
return bridgeId;
}

View File

@@ -173,14 +173,7 @@ public class HueMulator implements HueErrorStringSet {
}
if(groupId.equalsIgnoreCase("0")) {
List<DeviceDescriptor> deviceList = repository.findAll();
String[] theList = new String[deviceList.size()];
int i = 0;
for (DeviceDescriptor device : deviceList) {
theList[i] = device.getId();
i++;
}
GroupResponse theResponse = GroupResponse.createGroupResponse(theList);
GroupResponse theResponse = GroupResponse.createGroupResponse(repository.findAll());
return new Gson().toJson(theResponse, GroupResponse.class);
}
@@ -443,9 +436,9 @@ public class HueMulator implements HueErrorStringSet {
return theErrorResp.getTheErrors();
}
List<DeviceDescriptor> descriptorList = repository.findAll();
HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(), bridgeSettings.getWhitelist());
Map<String, DeviceResponse> deviceList = new HashMap<>();
List<DeviceDescriptor> descriptorList = repository.findAll();
if (descriptorList != null) {
descriptorList.forEach(descriptor -> {
DeviceResponse deviceResponse = DeviceResponse.createResponse(descriptor);
@@ -1256,8 +1249,8 @@ public class HueMulator implements HueErrorStringSet {
if(notFirstChange)
responseString = responseString + ",";
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/transitiontime\":" + state.getTransitiontime() + "}}";
if(deviceState != null)
deviceState.setTransitiontime(state.getTransitiontime());
// if(deviceState != null)
// deviceState.setTransitiontime(state.getTransitiontime());
notFirstChange = true;
}
@@ -1289,7 +1282,7 @@ public class HueMulator implements HueErrorStringSet {
private String validateWhitelistUser(String aUser, boolean strict) {
if(aUser == null ||aUser.equalsIgnoreCase("undefined") || aUser.equalsIgnoreCase("null") || aUser.equalsIgnoreCase(""))
return null;
String validUser = null;
boolean found = false;
if(bridgeSettings.getWhitelist() != null) {

View File

@@ -25,14 +25,14 @@ public class UpnpListener {
private BridgeControlDescriptor bridgeControl;
private boolean discoveryTemplateLatest;
private String discoveryTemplate = "HTTP/1.1 200 OK\r\n" +
"HOST: %s:%s" +
"HOST: %s:%s\r\n" +
"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";
"USN: uuid:2f402f80-da50-11e1-9b23-001788102201\r\n\r\n";
private String discoveryTemplate091516 = "HTTP/1.1 200 OK\r\n" +
"CACHE-CONTROL: max-age=86400\r\n" +
"EXT:\r\n" +
@@ -199,7 +199,8 @@ public class UpnpListener {
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);
else
log.debug("isSSDPDiscovery found message to be valid under strict rules - strict: " + strict);
return true;
}
else if (!strict)
@@ -209,7 +210,8 @@ public class UpnpListener {
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);
else
log.debug("isSSDPDiscovery found message to be valid under loose rules - strict: " + strict);
return true;
}
}
@@ -226,8 +228,10 @@ public class UpnpListener {
discoveryResponse = String.format(discoveryTemplate, Configuration.UPNP_MULTICAST_ADDRESS, Configuration.UPNP_DISCOVERY_PORT, responseAddress, httpServerPort, HuePublicConfig.createConfig("temp", responseAddress).getBridgeid());
else
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: discoveryResponse is <<<" + discoveryResponse + ">>>");
}
else
log.debug("sendUpnpResponse discovery template with address: " + responseAddress + " and port: " + httpServerPort);
DatagramPacket response = new DatagramPacket(discoveryResponse.getBytes(), discoveryResponse.length(), requester, sourcePort);