From c47e833ed9fa746f906a753031d2af61b1a93d8a Mon Sep 17 00:00:00 2001 From: lsiepel Date: Mon, 14 Aug 2023 22:08:22 +0200 Subject: [PATCH] [dscalarm] Fix checkstyle and warning (#15424) Signed-off-by: lsiepel --- .../dscalarm/internal/DSCAlarmMessage.java | 22 +++++++++---------- .../factory/DSCAlarmHandlerFactory.java | 4 +++- .../handler/DSCAlarmBaseBridgeHandler.java | 8 +++---- .../handler/DSCAlarmBaseThingHandler.java | 6 ++--- .../handler/PartitionThingHandler.java | 12 +++++----- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/DSCAlarmMessage.java b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/DSCAlarmMessage.java index 02247fa06c7..902ac1b93d7 100644 --- a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/DSCAlarmMessage.java +++ b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/DSCAlarmMessage.java @@ -219,13 +219,13 @@ public class DSCAlarmMessage { case PartitionArmed: /* 652 */ mode = message.substring(4); - if (mode.equals("0")) { + if ("0".equals(mode)) { name += " (Away)"; - } else if (mode.equals("1")) { + } else if ("1".equals(mode)) { name += " (Stay)"; - } else if (mode.equals("2")) { + } else if ("2".equals(mode)) { name += " (ZEA)"; - } else if (mode.equals("3")) { + } else if ("3".equals(mode)) { name += " (ZES)"; } messageType = DSCAlarmMessageType.PARTITION_EVENT; @@ -343,37 +343,37 @@ public class DSCAlarmMessage { sb.append(description); sb.append("\""); - if (!timeStamp.equals("")) { + if (!"".equals(timeStamp)) { sb.append(", Time Stamp: "); sb.append(timeStamp); } - if (!partition.equals("0")) { + if (!"0".equals(partition)) { sb.append(", Partition: "); sb.append(partition); } - if (!zone.equals("0")) { + if (!"0".equals(zone)) { sb.append(", Zone: "); sb.append(zone); } - if (!data.equals("")) { + if (!"".equals(data)) { sb.append(", Data: "); sb.append(data); } - if (!mode.equals("")) { + if (!"".equals(mode)) { sb.append(", Mode: "); sb.append(mode); } - if (!user.equals("")) { + if (!"".equals(user)) { sb.append(", user: "); sb.append(user); } - if (!error.equals("")) { + if (!"".equals(error)) { sb.append(", error: "); sb.append(error); } diff --git a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/factory/DSCAlarmHandlerFactory.java b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/factory/DSCAlarmHandlerFactory.java index 78b8ac4fabe..1b3f437e76a 100644 --- a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/factory/DSCAlarmHandlerFactory.java +++ b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/factory/DSCAlarmHandlerFactory.java @@ -306,7 +306,9 @@ public class DSCAlarmHandlerFactory extends BaseThingHandlerFactory { if (discoveryServiceRegistration != null) { DSCAlarmDiscoveryService discoveryService = (DSCAlarmDiscoveryService) bundleContext .getService(discoveryServiceRegistration.getReference()); - discoveryService.deactivate(); + if (discoveryService != null) { + discoveryService.deactivate(); + } discoveryServiceRegistration.unregister(); discoveryServiceRegistration = null; discoveryServiceRegistrations.remove(thingHandler.getThing().getUID()); diff --git a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/DSCAlarmBaseBridgeHandler.java b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/DSCAlarmBaseBridgeHandler.java index 850aca72271..db93d232d3f 100644 --- a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/DSCAlarmBaseBridgeHandler.java +++ b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/DSCAlarmBaseBridgeHandler.java @@ -477,16 +477,16 @@ public abstract class DSCAlarmBaseBridgeHandler extends BaseBridgeHandler { if (dscAlarmCode == DSCAlarmCode.LoginResponse) { String dscAlarmMessageData = dscAlarmMessage.getMessageInfo(DSCAlarmMessageInfoType.DATA); - if (dscAlarmMessageData.equals("3")) { + if ("3".equals(dscAlarmMessageData)) { sendCommand(DSCAlarmCode.NetworkLogin); // onConnected(); - } else if (dscAlarmMessageData.equals("1")) { + } else if ("1".equals(dscAlarmMessageData)) { onConnected(); } return; } else if (dscAlarmCode == DSCAlarmCode.CommandAcknowledge) { String dscAlarmMessageData = dscAlarmMessage.getMessageInfo(DSCAlarmMessageInfoType.DATA); - if (dscAlarmMessageData.equals("000")) { + if ("000".equals(dscAlarmMessageData)) { setBridgeStatus(true); } } @@ -764,7 +764,7 @@ public abstract class DSCAlarmBaseBridgeHandler extends BaseBridgeHandler { "sendCommand(): \'keystroke\' must be a single character string from 0 to 9, *, #, F, A, P, a to e, <, >, =, or ^, it was: {}", dscAlarmData[0]); break; - } else if (dscAlarmData[0].equals("L")) { /* Long Key Press */ + } else if ("L".equals(dscAlarmData[0])) { /* Long Key Press */ try { Thread.sleep(1500); data = "^"; diff --git a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/DSCAlarmBaseThingHandler.java b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/DSCAlarmBaseThingHandler.java index 35e0588a683..83a960670ce 100644 --- a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/DSCAlarmBaseThingHandler.java +++ b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/DSCAlarmBaseThingHandler.java @@ -106,7 +106,7 @@ public abstract class DSCAlarmBaseThingHandler extends BaseThingHandler { logger.debug("initializeThingHandler(): Initialize Thing Handler - {}", thing.getUID()); for (Channel channel : channels) { - if (channel.getAcceptedItemType().equals("DateTime")) { + if ("DateTime".equals(channel.getAcceptedItemType())) { updateChannel(channel.getUID(), 0, "0000010100"); } else { updateChannel(channel.getUID(), 0, ""); @@ -150,8 +150,8 @@ public abstract class DSCAlarmBaseThingHandler extends BaseThingHandler { ThingHandler handler = bridge.getHandler(); - if (handler instanceof DSCAlarmBaseBridgeHandler) { - this.dscAlarmBridgeHandler = (DSCAlarmBaseBridgeHandler) handler; + if (handler instanceof DSCAlarmBaseBridgeHandler dscAlarmBridgeHandler) { + this.dscAlarmBridgeHandler = dscAlarmBridgeHandler; } else { logger.debug("getDSCAlarmBridgeHandler(): Unable to get bridge handler!"); } diff --git a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/PartitionThingHandler.java b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/PartitionThingHandler.java index fdebc8d03f7..a749146ab2e 100644 --- a/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/PartitionThingHandler.java +++ b/bundles/org.openhab.binding.dscalarm/src/main/java/org/openhab/binding/dscalarm/internal/handler/PartitionThingHandler.java @@ -106,22 +106,22 @@ public class PartitionThingHandler extends DSCAlarmBaseThingHandler { switch (channelUID.getId()) { case PARTITION_ARM_MODE: int partitionNumber = getPartitionNumber(); - if (command.toString().equals("0")) { + if ("0".equals(command.toString())) { dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.PartitionDisarmControl, String.valueOf(partitionNumber)); - } else if (command.toString().equals("1")) { + } else if ("1".equals(command.toString())) { dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.PartitionArmControlAway, String.valueOf(partitionNumber)); - } else if (command.toString().equals("2")) { + } else if ("2".equals(command.toString())) { dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.PartitionArmControlStay, String.valueOf(partitionNumber)); - } else if (command.toString().equals("3")) { + } else if ("3".equals(command.toString())) { dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.PartitionArmControlZeroEntryDelay, String.valueOf(partitionNumber)); - } else if (command.toString().equals("4")) { + } else if ("4".equals(command.toString())) { dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.PartitionArmControlZeroEntryDelay, String.valueOf(partitionNumber)); - } else if (command.toString().equals("5")) { + } else if ("5".equals(command.toString())) { dscAlarmBridgeHandler.sendCommand(DSCAlarmCode.PartitionArmControlWithUserCode, String.valueOf(partitionNumber)); }