[doorbird] Warning and SAT cleanup (#15824)

* Warning and SAT clenaup

---------

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel 2023-11-04 10:31:52 +01:00 committed by GitHub
parent 0a5a9912a5
commit 6efa3d792c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 7 deletions

View File

@ -54,6 +54,7 @@ public class DoorbirdActions implements ThingActions {
@RuleAction(label = "restart the Doorbird", description = "Restarts the Doorbird device.") @RuleAction(label = "restart the Doorbird", description = "Restarts the Doorbird device.")
public void restart() { public void restart() {
logger.debug("Doorbird action 'restart' called"); logger.debug("Doorbird action 'restart' called");
DoorbellHandler handler = this.handler;
if (handler != null) { if (handler != null) {
handler.actionRestart(); handler.actionRestart();
} else { } else {
@ -68,6 +69,7 @@ public class DoorbirdActions implements ThingActions {
@RuleAction(label = "hangup a SIP call", description = "Hangup SIP call.") @RuleAction(label = "hangup a SIP call", description = "Hangup SIP call.")
public void sipHangup() { public void sipHangup() {
logger.debug("Doorbird action 'sipHangup' called"); logger.debug("Doorbird action 'sipHangup' called");
DoorbellHandler handler = this.handler;
if (handler != null) { if (handler != null) {
handler.actionSIPHangup(); handler.actionSIPHangup();
} else { } 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.") @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() { public @ActionOutput(name = "getRingTimeLimit", type = "java.lang.String") String getRingTimeLimit() {
logger.debug("Doorbird action 'getRingTimeLimit' called"); logger.debug("Doorbird action 'getRingTimeLimit' called");
DoorbellHandler handler = this.handler;
if (handler != null) { if (handler != null) {
return handler.actionGetRingTimeLimit(); return handler.actionGetRingTimeLimit();
} else { } 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.") @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() { public @ActionOutput(name = "getCallTimeLimit", type = "java.lang.String") String getCallTimeLimit() {
logger.debug("Doorbird action 'getCallTimeLimit' called"); logger.debug("Doorbird action 'getCallTimeLimit' called");
DoorbellHandler handler = this.handler;
if (handler != null) { if (handler != null) {
return handler.actionGetCallTimeLimit(); return handler.actionGetCallTimeLimit();
} else { } else {
@ -112,6 +116,7 @@ public class DoorbirdActions implements ThingActions {
@RuleAction(label = "get the last error code", description = "Get the value of LASTERRORCODE.") @RuleAction(label = "get the last error code", description = "Get the value of LASTERRORCODE.")
public @ActionOutput(name = "getLastErrorCode", type = "java.lang.String") String getLastErrorCode() { public @ActionOutput(name = "getLastErrorCode", type = "java.lang.String") String getLastErrorCode() {
logger.debug("Doorbird action 'getLastErrorCode' called"); logger.debug("Doorbird action 'getLastErrorCode' called");
DoorbellHandler handler = this.handler;
if (handler != null) { if (handler != null) {
return handler.actionGetLastErrorCode(); return handler.actionGetLastErrorCode();
} else { } else {
@ -127,6 +132,7 @@ public class DoorbirdActions implements ThingActions {
@RuleAction(label = "get the last error text", description = "Get the value of LASTERRORTEXT.") @RuleAction(label = "get the last error text", description = "Get the value of LASTERRORTEXT.")
public @ActionOutput(name = "getLastErrorText", type = "java.lang.String") String getLastErrorText() { public @ActionOutput(name = "getLastErrorText", type = "java.lang.String") String getLastErrorText() {
logger.debug("Doorbird action 'getLastErrorText' called"); logger.debug("Doorbird action 'getLastErrorText' called");
DoorbellHandler handler = this.handler;
if (handler != null) { if (handler != null) {
return handler.actionGetLastErrorText(); return handler.actionGetLastErrorText();
} else { } else {

View File

@ -54,6 +54,7 @@ public final class DoorbirdAPI {
private static final Gson GSON = new Gson(); private static final Gson GSON = new Gson();
private final Logger logger = LoggerFactory.getLogger(DoorbirdAPI.class); private final Logger logger = LoggerFactory.getLogger(DoorbirdAPI.class);
private static final int CHUNK_SIZE = 256;
private @Nullable Authorization authorization; private @Nullable Authorization authorization;
private @Nullable HttpClient httpClient; 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 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 // 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. // real time data, as if it were live spoken.
int CHUNK_SIZE = 256;
int nbByteRead = -1; int nbByteRead = -1;
long nextChunkSendTimeStamp = 0; long nextChunkSendTimeStamp = 0;
do { do {

View File

@ -365,9 +365,10 @@ public class DoorbellHandler extends BaseThingHandler {
} }
private void stopImageRefreshJob() { private void stopImageRefreshJob() {
ScheduledFuture<?> imageRefreshJob = this.imageRefreshJob;
if (imageRefreshJob != null) { if (imageRefreshJob != null) {
imageRefreshJob.cancel(true); imageRefreshJob.cancel(true);
imageRefreshJob = null; this.imageRefreshJob = null;
logger.debug("Canceling image refresh job"); logger.debug("Canceling image refresh job");
} }
} }
@ -378,9 +379,11 @@ public class DoorbellHandler extends BaseThingHandler {
} }
private void stopUDPListenerJob() { private void stopUDPListenerJob() {
ScheduledFuture<?> listenerJob = this.listenerJob;
if (listenerJob != null) { if (listenerJob != null) {
listenerJob.cancel(true); listenerJob.cancel(true);
udpListener.shutdown(); udpListener.shutdown();
this.listenerJob = null;
logger.debug("Canceling listener job"); logger.debug("Canceling listener job");
} }
} }
@ -390,19 +393,21 @@ public class DoorbellHandler extends BaseThingHandler {
if (offDelay == null) { if (offDelay == null) {
return; return;
} }
ScheduledFuture<?> doorbellOffJob = this.doorbellOffJob;
if (doorbellOffJob != null) { if (doorbellOffJob != null) {
doorbellOffJob.cancel(true); doorbellOffJob.cancel(true);
} }
doorbellOffJob = scheduler.schedule(() -> { this.doorbellOffJob = scheduler.schedule(() -> {
logger.debug("Update channel 'doorbell' to OFF for thing {}", getThing().getUID()); logger.debug("Update channel 'doorbell' to OFF for thing {}", getThing().getUID());
triggerChannel(CHANNEL_DOORBELL, CommonTriggerEvents.RELEASED); triggerChannel(CHANNEL_DOORBELL, CommonTriggerEvents.RELEASED);
}, offDelay, TimeUnit.SECONDS); }, offDelay, TimeUnit.SECONDS);
} }
private void stopDoorbellOffJob() { private void stopDoorbellOffJob() {
ScheduledFuture<?> doorbellOffJob = this.doorbellOffJob;
if (doorbellOffJob != null) { if (doorbellOffJob != null) {
doorbellOffJob.cancel(true); doorbellOffJob.cancel(true);
doorbellOffJob = null; this.doorbellOffJob = null;
logger.debug("Canceling doorbell off job"); logger.debug("Canceling doorbell off job");
} }
} }
@ -412,19 +417,21 @@ public class DoorbellHandler extends BaseThingHandler {
if (offDelay == null) { if (offDelay == null) {
return; return;
} }
ScheduledFuture<?> motionOffJob = this.motionOffJob;
if (motionOffJob != null) { if (motionOffJob != null) {
motionOffJob.cancel(true); motionOffJob.cancel(true);
} }
motionOffJob = scheduler.schedule(() -> { this.motionOffJob = scheduler.schedule(() -> {
logger.debug("Update channel 'motion' to OFF for thing {}", getThing().getUID()); logger.debug("Update channel 'motion' to OFF for thing {}", getThing().getUID());
updateState(CHANNEL_MOTION, OnOffType.OFF); updateState(CHANNEL_MOTION, OnOffType.OFF);
}, offDelay, TimeUnit.SECONDS); }, offDelay, TimeUnit.SECONDS);
} }
private void stopMotionOffJob() { private void stopMotionOffJob() {
ScheduledFuture<?> motionOffJob = this.motionOffJob;
if (motionOffJob != null) { if (motionOffJob != null) {
motionOffJob.cancel(true); motionOffJob.cancel(true);
motionOffJob = null; this.motionOffJob = null;
logger.debug("Canceling motion off job"); logger.debug("Canceling motion off job");
} }
} }

View File

@ -66,10 +66,11 @@ public class DoorbirdUdpListener extends Thread {
} }
public void shutdown() { public void shutdown() {
DatagramSocket socket = this.socket;
if (socket != null) { if (socket != null) {
socket.close(); socket.close();
logger.debug("Listener closing listener socket"); logger.debug("Listener closing listener socket");
socket = null; this.socket = null;
} }
} }