diff --git a/src/main/java/com/bwssystems/HABridge/HABridge.java b/src/main/java/com/bwssystems/HABridge/HABridge.java index db4ed6b..2c61c0a 100644 --- a/src/main/java/com/bwssystems/HABridge/HABridge.java +++ b/src/main/java/com/bwssystems/HABridge/HABridge.java @@ -75,7 +75,6 @@ public class HABridge { // start the upnp ssdp discovery listener theUpnpListener = new UpnpListener(bridgeSettings); - log.info("Done setup, application to run...."); theUpnpListener.startListening(); } } diff --git a/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java b/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java index cf65a8a..dbdc880 100644 --- a/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java +++ b/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java @@ -43,7 +43,7 @@ public class DeviceRepository { DeviceDescriptor theDevice = null; while (theIterator.hasNext()) { theDevice = theIterator.next(); - put(Integer.parseInt(theDevice.getId()), theDevice); + put(theDevice.getId(), theDevice); } } } @@ -62,17 +62,16 @@ public class DeviceRepository { return devices.get(id); } - private void put(int id, DeviceDescriptor aDescriptor) { - devices.put(String.valueOf(id), aDescriptor); + private void put(String id, DeviceDescriptor aDescriptor) { + devices.put(id, aDescriptor); } public void save(DeviceDescriptor aDescriptor) { - int id = random.nextInt(Integer.MAX_VALUE); if(aDescriptor.getId() != null) devices.remove(aDescriptor.getId()); else - aDescriptor.setId(String.valueOf(id)); - put(id, aDescriptor); + aDescriptor.setId(String.valueOf(random.nextInt(Integer.MAX_VALUE))); + put(aDescriptor.getId(), aDescriptor); JsonTransformer aRenderer = new JsonTransformer(); String jsonValue = aRenderer.render(findAll()); repositoryWriter(jsonValue, repositoryPath); diff --git a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java index 0d16da7..a0bb3a7 100644 --- a/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java +++ b/src/main/java/com/bwssystems/HABridge/devicemanagmeent/DeviceResource.java @@ -41,7 +41,7 @@ public class DeviceResource { } private void setupEndpoints() { - log.debug("Setting up endpoints"); + log.info("HABridge device management service started.... "); post(API_CONTEXT, "application/json", (request, response) -> { log.debug("Create a Device - request body: " + request.body()); DeviceDescriptor device = new Gson().fromJson(request.body(), DeviceDescriptor.class); diff --git a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java index f3994d8..12b2c40 100644 --- a/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java +++ b/src/main/java/com/bwssystems/HABridge/hue/HueMulator.java @@ -53,10 +53,11 @@ public class HueMulator { // This function sets up the sparkjava rest calls for the hue api private void setupEndpoints() { + log.info("Hue emulator service started...."); // 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"); - log.info("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<>(); for (DeviceDescriptor device : deviceList) { @@ -83,7 +84,7 @@ public class HueMulator { // http://ip_address:port/api/{userId} returns json objects for the full state get(HUE_CONTEXT + "/:userid", "application/json", (request, response) -> { String userId = request.params(":userid"); - log.info("hue api full state requested: " + userId + " from " + request.ip()); + log.debug("hue api full state requested: " + userId + " from " + request.ip()); List descriptorList = repository.findAll(); if (descriptorList == null) { response.status(404); @@ -107,13 +108,13 @@ public class HueMulator { get(HUE_CONTEXT + "/:userid/lights/:id", "application/json", (request, response) -> { String userId = request.params(":userid"); String lightId = request.params(":id"); - log.info("hue light requested: " + lightId + "for user: " + userId + " from " + request.ip()); + log.debug("hue light requested: " + lightId + " for user: " + userId + " from " + request.ip()); DeviceDescriptor device = repository.findOne(lightId); if (device == null) { response.status(404); return null; } else { - log.info("found device named: " + device.getName()); + log.debug("found device named: " + device.getName()); } DeviceResponse lightResponse = DeviceResponse.createResponse(device.getName(), device.getId()); @@ -129,7 +130,7 @@ public class HueMulator { */ String userId = request.params(":userid"); String lightId = request.params(":id"); - log.info("hue state change requested: " + userId + " from " + request.ip() + " body: " + request.body()); + log.debug("hue state change requested: " + userId + " from " + request.ip() + " body: " + request.body()); DeviceState state = null; try { @@ -143,7 +144,7 @@ public class HueMulator { DeviceDescriptor device = repository.findOne(lightId); if (device == null) { response.status(404); - log.error("Could not find devcie: " + lightId); + log.error("Could not find devcie: " + lightId + " for hue state change request: " + userId + " from " + request.ip() + " body: " + request.body()); return null; } @@ -189,12 +190,12 @@ public class HueMulator { // This function executes the url from the device repository against the vera protected boolean doHttpGETRequest(String url) { - log.info("calling GET on URL: " + url); + log.debug("calling GET on URL: " + url); HttpGet httpGet = new HttpGet(url); try { HttpResponse response = httpClient.execute(httpGet); EntityUtils.consume(response.getEntity()); //close out inputstream ignore content - log.info("GET on URL responded: " + response.getStatusLine().getStatusCode()); + log.debug("GET on URL responded: " + response.getStatusLine().getStatusCode()); if(response.getStatusLine().getStatusCode() == 200){ return true; } diff --git a/src/main/java/com/bwssystems/HABridge/upnp/UpnpListener.java b/src/main/java/com/bwssystems/HABridge/upnp/UpnpListener.java index 298cad5..09454c3 100644 --- a/src/main/java/com/bwssystems/HABridge/upnp/UpnpListener.java +++ b/src/main/java/com/bwssystems/HABridge/upnp/UpnpListener.java @@ -31,7 +31,7 @@ public class UpnpListener { } public void startListening(){ - log.info("Starting UPNP Discovery Listener"); + log.info("UPNP Discovery Listener started...."); try (DatagramSocket responseSocket = new DatagramSocket(upnpResponsePort); MulticastSocket upnpMulticastSocket = new MulticastSocket(UPNP_DISCOVERY_PORT);) { diff --git a/src/main/java/com/bwssystems/HABridge/upnp/UpnpSettingsResource.java b/src/main/java/com/bwssystems/HABridge/upnp/UpnpSettingsResource.java index fcacbb4..9477185 100644 --- a/src/main/java/com/bwssystems/HABridge/upnp/UpnpSettingsResource.java +++ b/src/main/java/com/bwssystems/HABridge/upnp/UpnpSettingsResource.java @@ -44,9 +44,10 @@ public class UpnpSettingsResource { } private void setupListener (BridgeSettings theSettings) { -// http://ip_address:port/upnp/:id/description.xml which returns the xml configuration for the location of the hue emulator + log.info("Hue description service started...."); +// http://ip_adress:port/description.xml which returns the xml configuration for the hue emulator get("/description.xml", "application/xml", (request, response) -> { - log.info("upnp device settings requested: " + request.params(":id") + " from " + request.ip()); + log.debug("upnp device settings requested: " + request.params(":id") + " from " + request.ip()); String portNumber = Integer.toString(request.port()); String filledTemplate = String.format(hueTemplate, theSettings.getUpnpConfigAddress(), portNumber, theSettings.getUpnpConfigAddress()); log.debug("upnp device settings response: " + filledTemplate);