mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 08:13:23 +00:00
Updatting upnp responses
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>com.bwssystems.HABridge</groupId>
|
<groupId>com.bwssystems.HABridge</groupId>
|
||||||
<artifactId>ha-bridge</artifactId>
|
<artifactId>ha-bridge</artifactId>
|
||||||
<version>3.1.0a</version>
|
<version>3.1.0b</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HA Bridge</name>
|
<name>HA Bridge</name>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class DeviceState {
|
|||||||
private String colormode;
|
private String colormode;
|
||||||
private boolean reachable;
|
private boolean reachable;
|
||||||
private List<Double> xy;
|
private List<Double> xy;
|
||||||
private int transitiontime;
|
// private int transitiontime;
|
||||||
|
|
||||||
public boolean isOn() {
|
public boolean isOn() {
|
||||||
return on;
|
return on;
|
||||||
@@ -98,13 +98,13 @@ public class DeviceState {
|
|||||||
public void setXy(List<Double> xy) {
|
public void setXy(List<Double> xy) {
|
||||||
this.xy = xy;
|
this.xy = xy;
|
||||||
}
|
}
|
||||||
public int getTransitiontime() {
|
// public int getTransitiontime() {
|
||||||
return transitiontime;
|
// return transitiontime;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void setTransitiontime(int transitiontime) {
|
// public void setTransitiontime(int transitiontime) {
|
||||||
this.transitiontime = transitiontime;
|
// this.transitiontime = transitiontime;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public static DeviceState createDeviceState() {
|
public static DeviceState createDeviceState() {
|
||||||
DeviceState newDeviceState = new DeviceState();
|
DeviceState newDeviceState = new DeviceState();
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
package com.bwssystems.HABridge.api.hue;
|
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 {
|
public class GroupResponse {
|
||||||
private DeviceState action;
|
private DeviceState action;
|
||||||
private String[] lights;
|
private String[] lights;
|
||||||
@@ -23,11 +28,17 @@ public class GroupResponse {
|
|||||||
this.name = name;
|
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();
|
GroupResponse theResponse = new GroupResponse();
|
||||||
theResponse.setAction(DeviceState.createDeviceState());
|
theResponse.setAction(DeviceState.createDeviceState());
|
||||||
theResponse.setName("Lightset 0");
|
theResponse.setName("Lightset 0");
|
||||||
theResponse.setLights(theLights);
|
theResponse.setLights(theList);
|
||||||
return theResponse;
|
return theResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,18 +71,18 @@ public class HuePublicConfig
|
|||||||
{
|
{
|
||||||
StringTokenizer st = new StringTokenizer(macAddr, ":");
|
StringTokenizer st = new StringTokenizer(macAddr, ":");
|
||||||
String bridgeId = "";
|
String bridgeId = "";
|
||||||
String port = null;
|
// String port = null;
|
||||||
while(st.hasMoreTokens()) {
|
while(st.hasMoreTokens()) {
|
||||||
bridgeId = bridgeId + st.nextToken();
|
bridgeId = bridgeId + st.nextToken();
|
||||||
}
|
}
|
||||||
if(ipAddr.contains(":")) {
|
// if(ipAddr.contains(":")) {
|
||||||
port = ipAddr.substring(ipAddr.indexOf(":"));
|
// port = ipAddr.substring(ipAddr.indexOf(":"));
|
||||||
BigInteger bigInt = BigInteger.valueOf(Integer.getInteger(port).intValue());
|
// BigInteger bigInt = BigInteger.valueOf(Integer.getInteger(port).intValue());
|
||||||
byte[] theBytes = bigInt.toByteArray();
|
// byte[] theBytes = bigInt.toByteArray();
|
||||||
bridgeId = bridgeId + DatatypeConverter.printHexBinary(theBytes);
|
// bridgeId = bridgeId + DatatypeConverter.printHexBinary(theBytes);
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
bridgeId = bridgeId + "0800";
|
// bridgeId = bridgeId + "0800";
|
||||||
return bridgeId;
|
return bridgeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -173,14 +173,7 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(groupId.equalsIgnoreCase("0")) {
|
if(groupId.equalsIgnoreCase("0")) {
|
||||||
List<DeviceDescriptor> deviceList = repository.findAll();
|
GroupResponse theResponse = GroupResponse.createGroupResponse(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);
|
|
||||||
return new Gson().toJson(theResponse, GroupResponse.class);
|
return new Gson().toJson(theResponse, GroupResponse.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,9 +436,9 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
return theErrorResp.getTheErrors();
|
return theErrorResp.getTheErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<DeviceDescriptor> descriptorList = repository.findAll();
|
||||||
HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(), bridgeSettings.getWhitelist());
|
HueApiResponse apiResponse = new HueApiResponse("Philips hue", bridgeSettings.getUpnpConfigAddress(), bridgeSettings.getWhitelist());
|
||||||
Map<String, DeviceResponse> deviceList = new HashMap<>();
|
Map<String, DeviceResponse> deviceList = new HashMap<>();
|
||||||
List<DeviceDescriptor> descriptorList = repository.findAll();
|
|
||||||
if (descriptorList != null) {
|
if (descriptorList != null) {
|
||||||
descriptorList.forEach(descriptor -> {
|
descriptorList.forEach(descriptor -> {
|
||||||
DeviceResponse deviceResponse = DeviceResponse.createResponse(descriptor);
|
DeviceResponse deviceResponse = DeviceResponse.createResponse(descriptor);
|
||||||
@@ -1256,8 +1249,8 @@ public class HueMulator implements HueErrorStringSet {
|
|||||||
if(notFirstChange)
|
if(notFirstChange)
|
||||||
responseString = responseString + ",";
|
responseString = responseString + ",";
|
||||||
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/transitiontime\":" + state.getTransitiontime() + "}}";
|
responseString = responseString + "{\"success\":{\"/lights/" + lightId + "/state/transitiontime\":" + state.getTransitiontime() + "}}";
|
||||||
if(deviceState != null)
|
// if(deviceState != null)
|
||||||
deviceState.setTransitiontime(state.getTransitiontime());
|
// deviceState.setTransitiontime(state.getTransitiontime());
|
||||||
notFirstChange = true;
|
notFirstChange = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,14 +25,14 @@ 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" +
|
"HOST: %s:%s\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" +
|
||||||
"SERVER: FreeRTOS/7.4.2 UPnP/1.0 IpBridge/1.10.0\r\n" +
|
"SERVER: FreeRTOS/7.4.2 UPnP/1.0 IpBridge/1.10.0\r\n" +
|
||||||
"hue-bridgeid: %s\r\n" +
|
"hue-bridgeid: %s\r\n" +
|
||||||
"ST: upnp:rootdevice\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" +
|
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" +
|
||||||
@@ -199,7 +199,8 @@ public class UpnpListener {
|
|||||||
log.info("Traceupnp: isSSDPDiscovery found message to be valid under strict rules - strict: " + strict);
|
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.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;
|
return true;
|
||||||
}
|
}
|
||||||
else if (!strict)
|
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: 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.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;
|
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());
|
discoveryResponse = String.format(discoveryTemplate, Configuration.UPNP_MULTICAST_ADDRESS, Configuration.UPNP_DISCOVERY_PORT, responseAddress, httpServerPort, HuePublicConfig.createConfig("temp", responseAddress).getBridgeid());
|
||||||
else
|
else
|
||||||
discoveryResponse = String.format(discoveryTemplate091516, 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);
|
||||||
|
log.info("Traceupnp: discoveryResponse is <<<" + discoveryResponse + ">>>");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
log.debug("sendUpnpResponse discovery template with address: " + responseAddress + " and port: " + httpServerPort);
|
log.debug("sendUpnpResponse discovery template with address: " + responseAddress + " and port: " + httpServerPort);
|
||||||
DatagramPacket response = new DatagramPacket(discoveryResponse.getBytes(), discoveryResponse.length(), requester, sourcePort);
|
DatagramPacket response = new DatagramPacket(discoveryResponse.getBytes(), discoveryResponse.length(), requester, sourcePort);
|
||||||
|
|||||||
Reference in New Issue
Block a user