[lcn] Refactor and fix null warnings (#9675)

Signed-off-by: Fabian Wolter <github@fabian-wolter.de>
This commit is contained in:
Fabian Wolter 2021-01-04 06:31:56 +01:00 committed by GitHub
parent bebc76e452
commit 4f1e915e50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 20 deletions

View 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) {

View 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<>();

View 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)) {

View 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) {

View 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());
}
}
}
}

View 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 {

View 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 {