diff --git a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java index 6e1a1decc..d335e194b 100644 --- a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java +++ b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/action/DoorbirdActions.java @@ -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 { diff --git a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/api/DoorbirdAPI.java b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/api/DoorbirdAPI.java index 51ba94257..94af5c436 100644 --- a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/api/DoorbirdAPI.java +++ b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/api/DoorbirdAPI.java @@ -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 { diff --git a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/handler/DoorbellHandler.java b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/handler/DoorbellHandler.java index e625fa8a5..45dadd0f7 100644 --- a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/handler/DoorbellHandler.java +++ b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/handler/DoorbellHandler.java @@ -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"); } } diff --git a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/listener/DoorbirdUdpListener.java b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/listener/DoorbirdUdpListener.java index 271fe803a..572938ed2 100644 --- a/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/listener/DoorbirdUdpListener.java +++ b/bundles/org.openhab.binding.doorbird/src/main/java/org/openhab/binding/doorbird/internal/listener/DoorbirdUdpListener.java @@ -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; } }