mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-18 16:17:30 +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>
|
||||
<artifactId>ha-bridge</artifactId>
|
||||
<version>1.1.0b</version>
|
||||
<version>1.1.0c</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>HA Bridge</name>
|
||||
|
||||
@@ -59,7 +59,7 @@ public class HueMulator {
|
||||
private HarmonyHandler myHarmony;
|
||||
private HttpClient httpClient;
|
||||
private ObjectMapper mapper;
|
||||
private Integer lastCount;
|
||||
private Map<String,Integer> 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<DeviceDescriptor> deviceList = repository.findAll();
|
||||
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++) {
|
||||
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 = "<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);
|
||||
|
||||
response.header("Access-Control-Allow-Origin", request.headers("Origin"));
|
||||
|
||||
@@ -30,7 +30,7 @@ public class VeraInfo {
|
||||
|
||||
public VeraInfo(String addressString, Boolean isValidVera) {
|
||||
super();
|
||||
httpClient = HttpClients.createMinimal();
|
||||
httpClient = HttpClients.createDefault();
|
||||
veraAddressString = addressString;
|
||||
validVera = isValidVera;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user