]> git.basschouten.com Git - openhab-addons.git/commitdiff
[doorbird] Warning and SAT cleanup (#15824)
authorlsiepel <leosiepel@gmail.com>
Sat, 4 Nov 2023 09:31:52 +0000 (10:31 +0100)
committerGitHub <noreply@github.com>
Sat, 4 Nov 2023 09:31:52 +0000 (10:31 +0100)
* Warning and SAT clenaup

---------

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java
bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/api/DoorbirdAPI.java
bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/handler/DoorbellHandler.java
bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/listener/DoorbirdUdpListener.java

index 6e1a1decc5e4cc478e9522b1fee70a75fe505625..d335e194bdfcfd882dc57948a16c5a37c05f47f4 100644 (file)
@@ -54,6 +54,7 @@ public class DoorbirdActions implements ThingActions {
     @RuleAction(label = "restart the Doorbird", description = "Restarts the Doorbird device.")
     public void restart() {
         logger.debug("Doorbird action 'restart' called");
+        DoorbellHandler handler = this.handler;
         if (handler != null) {
             handler.actionRestart();
         } else {
@@ -68,6 +69,7 @@ public class DoorbirdActions implements ThingActions {
     @RuleAction(label = "hangup a SIP call", description = "Hangup SIP call.")
     public void sipHangup() {
         logger.debug("Doorbird action 'sipHangup' called");
+        DoorbellHandler handler = this.handler;
         if (handler != null) {
             handler.actionSIPHangup();
         } else {
@@ -82,6 +84,7 @@ public class DoorbirdActions implements ThingActions {
     @RuleAction(label = "get the ring time limit", description = "Get the value of RING_TIME_LIMIT.")
     public @ActionOutput(name = "getRingTimeLimit", type = "java.lang.String") String getRingTimeLimit() {
         logger.debug("Doorbird action 'getRingTimeLimit' called");
+        DoorbellHandler handler = this.handler;
         if (handler != null) {
             return handler.actionGetRingTimeLimit();
         } else {
@@ -97,6 +100,7 @@ public class DoorbirdActions implements ThingActions {
     @RuleAction(label = "get the call time limit", description = "Get the value of CALL_TIME_LIMIT.")
     public @ActionOutput(name = "getCallTimeLimit", type = "java.lang.String") String getCallTimeLimit() {
         logger.debug("Doorbird action 'getCallTimeLimit' called");
+        DoorbellHandler handler = this.handler;
         if (handler != null) {
             return handler.actionGetCallTimeLimit();
         } else {
@@ -112,6 +116,7 @@ public class DoorbirdActions implements ThingActions {
     @RuleAction(label = "get the last error code", description = "Get the value of LASTERRORCODE.")
     public @ActionOutput(name = "getLastErrorCode", type = "java.lang.String") String getLastErrorCode() {
         logger.debug("Doorbird action 'getLastErrorCode' called");
+        DoorbellHandler handler = this.handler;
         if (handler != null) {
             return handler.actionGetLastErrorCode();
         } else {
@@ -127,6 +132,7 @@ public class DoorbirdActions implements ThingActions {
     @RuleAction(label = "get the last error text", description = "Get the value of LASTERRORTEXT.")
     public @ActionOutput(name = "getLastErrorText", type = "java.lang.String") String getLastErrorText() {
         logger.debug("Doorbird action 'getLastErrorText' called");
+        DoorbellHandler handler = this.handler;
         if (handler != null) {
             return handler.actionGetLastErrorText();
         } else {
index 51ba942577cdafc649eebb8b331937d7b9bf70db..94af5c436862538acd357ccf9bf2fa246485bdd9 100644 (file)
@@ -54,6 +54,7 @@ public final class DoorbirdAPI {
     private static final Gson GSON = new Gson();
 
     private final Logger logger = LoggerFactory.getLogger(DoorbirdAPI.class);
+    private static final int CHUNK_SIZE = 256;
 
     private @Nullable Authorization authorization;
     private @Nullable HttpClient httpClient;
@@ -191,7 +192,6 @@ public final class DoorbirdAPI {
             // It is crucial to send data in small chunks to not overload the doorbird
             // It means that we have to wait the appropriate amount of time between chunk to send
             // real time data, as if it were live spoken.
-            int CHUNK_SIZE = 256;
             int nbByteRead = -1;
             long nextChunkSendTimeStamp = 0;
             do {
index e625fa8a5e4009edba403cceddc2adc3e844a415..45dadd0f78b08d5c436c09ca2e3a3af89988394d 100644 (file)
@@ -365,9 +365,10 @@ public class DoorbellHandler extends BaseThingHandler {
     }
 
     private void stopImageRefreshJob() {
+        ScheduledFuture<?> imageRefreshJob = this.imageRefreshJob;
         if (imageRefreshJob != null) {
             imageRefreshJob.cancel(true);
-            imageRefreshJob = null;
+            this.imageRefreshJob = null;
             logger.debug("Canceling image refresh job");
         }
     }
@@ -378,9 +379,11 @@ public class DoorbellHandler extends BaseThingHandler {
     }
 
     private void stopUDPListenerJob() {
+        ScheduledFuture<?> listenerJob = this.listenerJob;
         if (listenerJob != null) {
             listenerJob.cancel(true);
             udpListener.shutdown();
+            this.listenerJob = null;
             logger.debug("Canceling listener job");
         }
     }
@@ -390,19 +393,21 @@ public class DoorbellHandler extends BaseThingHandler {
         if (offDelay == null) {
             return;
         }
+        ScheduledFuture<?> doorbellOffJob = this.doorbellOffJob;
         if (doorbellOffJob != null) {
             doorbellOffJob.cancel(true);
         }
-        doorbellOffJob = scheduler.schedule(() -> {
+        this.doorbellOffJob = scheduler.schedule(() -> {
             logger.debug("Update channel 'doorbell' to OFF for thing {}", getThing().getUID());
             triggerChannel(CHANNEL_DOORBELL, CommonTriggerEvents.RELEASED);
         }, offDelay, TimeUnit.SECONDS);
     }
 
     private void stopDoorbellOffJob() {
+        ScheduledFuture<?> doorbellOffJob = this.doorbellOffJob;
         if (doorbellOffJob != null) {
             doorbellOffJob.cancel(true);
-            doorbellOffJob = null;
+            this.doorbellOffJob = null;
             logger.debug("Canceling doorbell off job");
         }
     }
@@ -412,19 +417,21 @@ public class DoorbellHandler extends BaseThingHandler {
         if (offDelay == null) {
             return;
         }
+        ScheduledFuture<?> motionOffJob = this.motionOffJob;
         if (motionOffJob != null) {
             motionOffJob.cancel(true);
         }
-        motionOffJob = scheduler.schedule(() -> {
+        this.motionOffJob = scheduler.schedule(() -> {
             logger.debug("Update channel 'motion' to OFF for thing {}", getThing().getUID());
             updateState(CHANNEL_MOTION, OnOffType.OFF);
         }, offDelay, TimeUnit.SECONDS);
     }
 
     private void stopMotionOffJob() {
+        ScheduledFuture<?> motionOffJob = this.motionOffJob;
         if (motionOffJob != null) {
             motionOffJob.cancel(true);
-            motionOffJob = null;
+            this.motionOffJob = null;
             logger.debug("Canceling motion off job");
         }
     }
index 271fe803af941b3975e5458cc145f1caa17e3691..572938ed248063cec89aa1ec049b92d5ff52f127 100644 (file)
@@ -66,10 +66,11 @@ public class DoorbirdUdpListener extends Thread {
     }
 
     public void shutdown() {
+        DatagramSocket socket = this.socket;
         if (socket != null) {
             socket.close();
             logger.debug("Listener closing listener socket");
-            socket = null;
+            this.socket = null;
         }
     }