From 5e2351bc4d24bcf8f407d07ae3f0c4233102fd5a Mon Sep 17 00:00:00 2001 From: jannegpriv Date: Wed, 27 May 2020 22:16:36 +0200 Subject: [PATCH] Updated after code review. Signed-off-by: Jan Gustafsson (github: jannegpriv) --- .../verisure/internal/VerisureSession.java | 24 +++++++------------ .../handler/VerisureThingHandler.java | 10 ++++---- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/VerisureSession.java b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/VerisureSession.java index 4a63fc3253bdf..ef66feaf7fbf5 100644 --- a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/VerisureSession.java +++ b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/VerisureSession.java @@ -332,7 +332,7 @@ private boolean areWeLoggedIn() { return null; } - private @Nullable T postJSONVerisureAPI(String url, String data, Class jsonClass) { + private @Nullable T postJSONVerisureAPI(String url, String data, Class jsonClass) { for (int cnt = 0; cnt < APISERVERLIST.size(); cnt++) { ContentResponse response = postVerisureAPI(apiServerInUse + url, data, Boolean.TRUE); if (response != null) { @@ -537,9 +537,7 @@ private String createOperationJSON(String operation, VariablesDTO variables, Str operationJSON.setOperationName(operation); operationJSON.setVariables(variables); operationJSON.setQuery(query); - List list = Collections.singletonList(operationJSON); - - return gson.toJson(list); + return gson.toJson(Collections.singletonList(operationJSON)); } private synchronized void updateAlarmStatus(VerisureInstallation installation) { @@ -586,8 +584,7 @@ private synchronized void updateSmartLockStatus(VerisureInstallation installatio doorLockList.forEach(doorLock -> { VerisureSmartLocksDTO slThing = new VerisureSmartLocksDTO(); VerisureSmartLocksDTO.Installation inst = new VerisureSmartLocksDTO.Installation(); - List list = Collections.singletonList(doorLock); - inst.setDoorlocks(list); + inst.setDoorlocks(Collections.singletonList(doorLock)); VerisureSmartLocksDTO.Data data = new VerisureSmartLocksDTO.Data(); data.setInstallation(inst); slThing.setData(data); @@ -629,8 +626,7 @@ private synchronized void updateSmartPlugStatus(VerisureInstallation installatio smartPlugList.forEach(smartPlug -> { VerisureSmartPlugsDTO spThing = new VerisureSmartPlugsDTO(); VerisureSmartPlugsDTO.Installation inst = new VerisureSmartPlugsDTO.Installation(); - List list = Collections.singletonList(smartPlug); - inst.setSmartplugs(list); + inst.setSmartplugs(Collections.singletonList(smartPlug)); VerisureSmartPlugsDTO.Data data = new VerisureSmartPlugsDTO.Data(); data.setInstallation(inst); spThing.setData(data); @@ -685,8 +681,7 @@ private synchronized void updateClimateStatus(VerisureInstallation installation) } VerisureClimatesDTO cThing = new VerisureClimatesDTO(); VerisureClimatesDTO.Installation inst = new VerisureClimatesDTO.Installation(); - List list = Collections.singletonList(climate); - inst.setClimates(list); + inst.setClimates(Collections.singletonList(climate)); VerisureClimatesDTO.Data data = new VerisureClimatesDTO.Data(); data.setInstallation(inst); cThing.setData(data); @@ -723,8 +718,7 @@ private synchronized void updateDoorWindowStatus(VerisureInstallation installati doorWindowList.forEach(doorWindow -> { VerisureDoorWindowsDTO dThing = new VerisureDoorWindowsDTO(); VerisureDoorWindowsDTO.Installation inst = new VerisureDoorWindowsDTO.Installation(); - List list = Collections.singletonList(doorWindow); - inst.setDoorWindows(list); + inst.setDoorWindows(Collections.singletonList(doorWindow)); VerisureDoorWindowsDTO.Data data = new VerisureDoorWindowsDTO.Data(); data.setInstallation(inst); dThing.setData(data); @@ -789,8 +783,7 @@ private synchronized void updateUserPresenceStatus(VerisureInstallation installa if (localUserTrackingStatus != null && localUserTrackingStatus.equals("ACTIVE")) { VerisureUserPresencesDTO upThing = new VerisureUserPresencesDTO(); VerisureUserPresencesDTO.Installation inst = new VerisureUserPresencesDTO.Installation(); - List list = Collections.singletonList(userTracking); - inst.setUserTrackings(list); + inst.setUserTrackings(Collections.singletonList(userTracking)); VerisureUserPresencesDTO.Data data = new VerisureUserPresencesDTO.Data(); data.setInstallation(inst); upThing.setData(data); @@ -824,8 +817,7 @@ private synchronized void updateMiceDetectionStatus(VerisureInstallation install miceList.forEach(mouse -> { VerisureMiceDetectionDTO miceThing = new VerisureMiceDetectionDTO(); VerisureMiceDetectionDTO.Installation inst = new VerisureMiceDetectionDTO.Installation(); - List list = Collections.singletonList(mouse); - inst.setMice(list); + inst.setMice(Collections.singletonList(mouse)); VerisureMiceDetectionDTO.Data data = new VerisureMiceDetectionDTO.Data(); data.setInstallation(inst); miceThing.setData(data); diff --git a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureThingHandler.java b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureThingHandler.java index 472acb16ba2dd..fbce3415f1e1a 100644 --- a/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureThingHandler.java +++ b/bundles/org.openhab.binding.verisure/src/main/java/org/openhab/binding/verisure/internal/handler/VerisureThingHandler.java @@ -100,12 +100,10 @@ public void initialize() { config = getConfigAs(VerisureThingConfiguration.class); // Set status to UNKNOWN and let background task set correct status updateStatus(ThingStatus.UNKNOWN); - scheduler.execute(() -> { - Bridge bridge = getBridge(); - if (bridge != null) { - this.bridgeStatusChanged(bridge.getStatusInfo()); - } - }); + Bridge bridge = getBridge(); + if (bridge != null) { + this.bridgeStatusChanged(bridge.getStatusInfo()); + } } @Override