From 7a812d6e6bfe83eea6ef5d80d0080254a0261b4f Mon Sep 17 00:00:00 2001 From: Admin Date: Mon, 23 Nov 2015 15:14:38 -0600 Subject: [PATCH] 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. --- pom.xml | 2 +- .../bwssystems/HABridge/hue/HueMulator.java | 22 ++++++++++++++++--- .../java/com/bwssystems/vera/VeraInfo.java | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 9575212..41e7721 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.bwssystems.HABridge ha-bridge - 1.1.0b + 1.1.0c jar HA Bridge diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index 74be736..dda0d15 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -59,7 +59,7 @@ public class HueMulator { private HarmonyHandler myHarmony; private HttpClient httpClient; private ObjectMapper mapper; - private Integer lastCount; + private Map lastUserIdCount; private BridgeSettings bridgeSettings; @@ -70,7 +70,7 @@ public class HueMulator { repository = aDeviceRepository; myHarmony = theHandler; bridgeSettings = theBridgeSettings; - lastCount = 0; + lastUserIdCount = new HashMap<>(); } // 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 get(HUE_CONTEXT + "/:userid/lights", "application/json", (request, response) -> { 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()); List deviceList = repository.findAll(); Map 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++) { - if(lastCount == deviceList.size()) + if(lastCount >= deviceList.size()) + { lastCount = 0; + break; + } DeviceDescriptor device = deviceList.get(lastCount); DeviceResponse deviceResponse = DeviceResponse.createResponse(device.getName(), device.getId()); deviceResponseMap.put(device.getId(), deviceResponse); lastCount++; } + lastUserIdCount.replace(userId, lastCount); response.type("application/json; charset=utf-8"); response.status(HttpStatus.SC_OK); return deviceResponseMap; @@ -110,6 +122,8 @@ public class HueMulator { String newUser = 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()); if(request.body() != null && !request.body().isEmpty()) { @@ -122,6 +136,8 @@ public class HueMulator { if(aDeviceType == null) aDeviceType = ""; + 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); response.header("Access-Control-Allow-Origin", request.headers("Origin")); diff --git a/src/main/java/com/bwssystems/vera/VeraInfo.java b/src/main/java/com/bwssystems/vera/VeraInfo.java index 50ee625..e1989d0 100644 --- a/src/main/java/com/bwssystems/vera/VeraInfo.java +++ b/src/main/java/com/bwssystems/vera/VeraInfo.java @@ -30,7 +30,7 @@ public class VeraInfo { public VeraInfo(String addressString, Boolean isValidVera) { super(); - httpClient = HttpClients.createMinimal(); + httpClient = HttpClients.createDefault(); veraAddressString = addressString; validVera = isValidVera; }