mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-19 00:20:26 +00:00
Updated VeraInfo to use default http client. Finished work on doling out
devices in the resource manager. Caveat, this did not work well with the echo. Next version will roll this back.
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>1.1.0b</version>
|
<version>1.1.0c</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>HA Bridge</name>
|
<name>HA Bridge</name>
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class HueMulator {
|
|||||||
private HarmonyHandler myHarmony;
|
private HarmonyHandler myHarmony;
|
||||||
private HttpClient httpClient;
|
private HttpClient httpClient;
|
||||||
private ObjectMapper mapper;
|
private ObjectMapper mapper;
|
||||||
private Integer lastCount;
|
private Map<String,Integer> lastUserIdCount;
|
||||||
private BridgeSettings bridgeSettings;
|
private BridgeSettings bridgeSettings;
|
||||||
|
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ public class HueMulator {
|
|||||||
repository = aDeviceRepository;
|
repository = aDeviceRepository;
|
||||||
myHarmony = theHandler;
|
myHarmony = theHandler;
|
||||||
bridgeSettings = theBridgeSettings;
|
bridgeSettings = theBridgeSettings;
|
||||||
lastCount = 0;
|
lastUserIdCount = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function sets up the sparkjava rest calls for the hue api
|
// This function sets up the sparkjava rest calls for the hue api
|
||||||
@@ -79,17 +79,29 @@ public class HueMulator {
|
|||||||
// http://ip_address:port/api/{userId}/lights returns json objects of all lights configured
|
// http://ip_address:port/api/{userId}/lights returns json objects of all lights configured
|
||||||
get(HUE_CONTEXT + "/:userid/lights", "application/json", (request, response) -> {
|
get(HUE_CONTEXT + "/:userid/lights", "application/json", (request, response) -> {
|
||||||
String userId = request.params(":userid");
|
String userId = request.params(":userid");
|
||||||
|
if(bridgeSettings.isTraceupnp())
|
||||||
|
log.info("Traceupnp: hue lights list requested: " + userId + " from " + request.ip());
|
||||||
log.debug("hue lights list requested: " + userId + " from " + request.ip());
|
log.debug("hue lights list requested: " + userId + " from " + request.ip());
|
||||||
List<DeviceDescriptor> deviceList = repository.findAll();
|
List<DeviceDescriptor> deviceList = repository.findAll();
|
||||||
Map<String, DeviceResponse> deviceResponseMap = new HashMap<>();
|
Map<String, DeviceResponse> deviceResponseMap = new HashMap<>();
|
||||||
|
Integer lastCount = lastUserIdCount.get(userId);
|
||||||
|
if(lastCount == null)
|
||||||
|
{
|
||||||
|
lastCount = new Integer(0);
|
||||||
|
lastUserIdCount.put(userId, lastCount);
|
||||||
|
}
|
||||||
for (int i = 0; i < bridgeSettings.getUpnpResponseDevices(); i++) {
|
for (int i = 0; i < bridgeSettings.getUpnpResponseDevices(); i++) {
|
||||||
if(lastCount == deviceList.size())
|
if(lastCount >= deviceList.size())
|
||||||
|
{
|
||||||
lastCount = 0;
|
lastCount = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
DeviceDescriptor device = deviceList.get(lastCount);
|
DeviceDescriptor device = deviceList.get(lastCount);
|
||||||
DeviceResponse deviceResponse = DeviceResponse.createResponse(device.getName(), device.getId());
|
DeviceResponse deviceResponse = DeviceResponse.createResponse(device.getName(), device.getId());
|
||||||
deviceResponseMap.put(device.getId(), deviceResponse);
|
deviceResponseMap.put(device.getId(), deviceResponse);
|
||||||
lastCount++;
|
lastCount++;
|
||||||
}
|
}
|
||||||
|
lastUserIdCount.replace(userId, lastCount);
|
||||||
response.type("application/json; charset=utf-8");
|
response.type("application/json; charset=utf-8");
|
||||||
response.status(HttpStatus.SC_OK);
|
response.status(HttpStatus.SC_OK);
|
||||||
return deviceResponseMap;
|
return deviceResponseMap;
|
||||||
@@ -110,6 +122,8 @@ public class HueMulator {
|
|||||||
String newUser = null;
|
String newUser = null;
|
||||||
String aDeviceType = null;
|
String aDeviceType = null;
|
||||||
|
|
||||||
|
if(bridgeSettings.isTraceupnp())
|
||||||
|
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());
|
log.debug("hue api user create requested: " + request.body() + " from " + request.ip());
|
||||||
|
|
||||||
if(request.body() != null && !request.body().isEmpty()) {
|
if(request.body() != null && !request.body().isEmpty()) {
|
||||||
@@ -122,6 +136,8 @@ public class HueMulator {
|
|||||||
|
|
||||||
if(aDeviceType == null)
|
if(aDeviceType == null)
|
||||||
aDeviceType = "<not given>";
|
aDeviceType = "<not given>";
|
||||||
|
if(bridgeSettings.isTraceupnp())
|
||||||
|
log.info("Traceupnp: hue api user create requested for device type: " + aDeviceType + " and username: " + newUser);
|
||||||
log.debug("hue api user create requested for device type: " + aDeviceType + " and username: " + newUser);
|
log.debug("hue api user create requested for device type: " + aDeviceType + " and username: " + newUser);
|
||||||
|
|
||||||
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
|
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class VeraInfo {
|
|||||||
|
|
||||||
public VeraInfo(String addressString, Boolean isValidVera) {
|
public VeraInfo(String addressString, Boolean isValidVera) {
|
||||||
super();
|
super();
|
||||||
httpClient = HttpClients.createMinimal();
|
httpClient = HttpClients.createDefault();
|
||||||
veraAddressString = addressString;
|
veraAddressString = addressString;
|
||||||
validVera = isValidVera;
|
validVera = isValidVera;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user