]> git.basschouten.com Git - openhab-addons.git/commitdiff
[lcn] Refactor and fix null warnings (#9675)
authorFabian Wolter <github@fabian-wolter.de>
Mon, 4 Jan 2021 05:31:56 +0000 (06:31 +0100)
committerGitHub <noreply@github.com>
Mon, 4 Jan 2021 05:31:56 +0000 (21:31 -0800)
Signed-off-by: Fabian Wolter <github@fabian-wolter.de>
bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnHandlerFactory.java
bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnModuleDiscoveryService.java
bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnModuleHandler.java
bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/connection/AbstractStateMachine.java
bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/connection/Connection.java
bundles/org.openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/pchkdiscovery/LcnPchkDiscoveryService.java
bundles/org.openhab.binding.lcn/src/test/java/org/openhab/binding/lcn/internal/subhandler/AbstractTestLcnModuleSubHandler.java

index 5c4e0ffe630389316c17fb6265a9757c96224ca9..72b02825b1b63d06c5ba5c80b97c4840fd86a151 100644 (file)
@@ -14,10 +14,7 @@ package org.openhab.binding.lcn.internal;
 
 import static org.openhab.binding.lcn.internal.LcnBindingConstants.*;
 
-import java.util.Collections;
 import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
@@ -38,8 +35,8 @@ import org.osgi.service.component.annotations.Component;
 @NonNullByDefault
 @Component(configurationPid = "binding.lcn", service = ThingHandlerFactory.class)
 public class LcnHandlerFactory extends BaseThingHandlerFactory {
-    private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet(
-            Stream.of(THING_TYPE_PCK_GATEWAY, THING_TYPE_MODULE, THING_TYPE_GROUP).collect(Collectors.toSet()));
+    private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_PCK_GATEWAY,
+            THING_TYPE_MODULE, THING_TYPE_GROUP);
 
     @Override
     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
index 393f040b6a2b8935ece1a68a3a1ee2e8346e0458..bc3f0d646deee32e8d4d0999edc75de70ac57b97 100644 (file)
@@ -12,7 +12,6 @@
  */
 package org.openhab.binding.lcn.internal;
 
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
@@ -25,8 +24,6 @@ import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
@@ -69,8 +66,7 @@ public class LcnModuleDiscoveryService extends AbstractDiscoveryService
     private static final int MODULE_NAME_PART_COUNT = 2;
     private static final int DISCOVERY_TIMEOUT_SEC = 90;
     private static final int ACK_TIMEOUT_MS = 1000;
-    private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
-            .unmodifiableSet(Stream.of(LcnBindingConstants.THING_TYPE_MODULE).collect(Collectors.toSet()));
+    private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(LcnBindingConstants.THING_TYPE_MODULE);
     private @Nullable PckGatewayHandler bridgeHandler;
     private final Map<LcnAddrMod, @Nullable Map<Integer, String>> moduleNames = new HashMap<>();
     private final Map<LcnAddrMod, DiscoveryResultBuilder> discoveryResultBuilders = new ConcurrentHashMap<>();
index 8b5a2a7af525e3c7d05c2e8807db84a40fdb2897..e8122132e408397a161c90d81b5e7f0ac62c2870 100644 (file)
@@ -157,7 +157,6 @@ public class LcnModuleHandler extends BaseThingHandler {
      *
      * @throws LcnException when the handler is not initialized
      */
-    @SuppressWarnings("null")
     protected void requestFirmwareVersionAndSerialNumberIfNotSet() throws LcnException {
         String serialNumber = getThing().getProperties().get(Thing.PROPERTY_SERIAL_NUMBER);
         if (serialNumber == null || serialNumber.isEmpty()) {
@@ -241,7 +240,6 @@ public class LcnModuleHandler extends BaseThingHandler {
      *
      * @param pck the message without line termination
      */
-    @SuppressWarnings("null")
     public void handleStatusMessage(String pck) {
         for (AbstractLcnModuleSubHandler handler : subHandlers.values()) {
             if (handler.tryParse(pck)) {
index 1d1c87941b28a38d03f63287c2d873c91afb33fd..3a60c507e66187f40daf0a35dd909b0d31bad023 100644 (file)
@@ -55,7 +55,7 @@ public abstract class AbstractStateMachine<T extends AbstractStateMachine<T, U>,
 
         state = newState;
 
-        state.startWorking();
+        newState.startWorking();
     }
 
     protected boolean isStateActive(AbstractState<?, ?> otherState) {
index b53fd4a432be2d8df6898264023241c889e458ee..5d46f4cce39f44a27fbe8f72848fb3a15e862ad8 100644 (file)
@@ -21,7 +21,13 @@ import java.nio.channels.Channel;
 import java.nio.channels.CompletionHandler;
 import java.time.Instant;
 import java.time.temporal.ChronoUnit;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Queue;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ScheduledExecutorService;
@@ -133,7 +139,10 @@ public class Connection {
     public void onAck(LcnAddrMod addr, int code) {
         synchronized (modData) {
             if (modData.containsKey(addr)) {
-                modData.get(addr).onAck(code, this, this.settings.getTimeout(), System.nanoTime());
+                ModInfo modInfo = modData.get(addr);
+                if (modInfo != null) {
+                    modInfo.onAck(code, this, this.settings.getTimeout(), System.nanoTime());
+                }
             }
         }
     }
index e13ecc1d269e20c62cd85cd947173da051222646..1780e327ade95036429b9532afbecc5bfaff4584 100644 (file)
@@ -25,8 +25,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.openhab.binding.lcn.internal.LcnBindingConstants;
@@ -63,8 +61,8 @@ public class LcnPchkDiscoveryService extends AbstractDiscoveryService {
     private static final String PCHK_DISCOVERY_MULTICAST_ADDRESS = "234.5.6.7";
     private static final int PCHK_DISCOVERY_PORT = 4220;
     private static final int INTERFACE_TIMEOUT_SEC = 2;
-    private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
-            .unmodifiableSet(Stream.of(LcnBindingConstants.THING_TYPE_PCK_GATEWAY).collect(Collectors.toSet()));
+    private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set
+            .of(LcnBindingConstants.THING_TYPE_PCK_GATEWAY);
     private static final String DISCOVER_REQUEST = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ServicesRequest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"servicesrequest.xsd\"><Version major=\"1\" minor=\"0\" /><Requester requestId=\"1\" type=\"openHAB\" major=\"1\" minor=\"0\">openHAB</Requester><Requests><Request xsi:type=\"EnumServices\" major=\"1\" minor=\"0\" name=\"LcnPchkBus\" /></Requests></ServicesRequest>";
 
     public LcnPchkDiscoveryService() throws IllegalArgumentException {
index ad7f5ccf0468b61e4f03a2b3c787cd76e872f0d9..fd8abd27af8006d3403522f439141ac93ee6222c 100644 (file)
@@ -29,7 +29,7 @@ import org.openhab.binding.lcn.internal.connection.ModInfo;
  * @author Fabian Wolter - Initial contribution
  */
 @ExtendWith(MockitoExtension.class)
-@MockitoSettings(strictness = Strictness.WARN)
+@MockitoSettings(strictness = Strictness.LENIENT)
 @NonNullByDefault
 public class AbstractTestLcnModuleSubHandler {