[lcn] Refactor and fix null warnings (#9675)
Signed-off-by: Fabian Wolter <github@fabian-wolter.de>
This commit is contained in:
parent
bebc76e452
commit
4f1e915e50
|
@ -14,10 +14,7 @@ package org.openhab.binding.lcn.internal;
|
||||||
|
|
||||||
import static org.openhab.binding.lcn.internal.LcnBindingConstants.*;
|
import static org.openhab.binding.lcn.internal.LcnBindingConstants.*;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Set;
|
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.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
@ -38,8 +35,8 @@ import org.osgi.service.component.annotations.Component;
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
@Component(configurationPid = "binding.lcn", service = ThingHandlerFactory.class)
|
@Component(configurationPid = "binding.lcn", service = ThingHandlerFactory.class)
|
||||||
public class LcnHandlerFactory extends BaseThingHandlerFactory {
|
public class LcnHandlerFactory extends BaseThingHandlerFactory {
|
||||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet(
|
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_PCK_GATEWAY,
|
||||||
Stream.of(THING_TYPE_PCK_GATEWAY, THING_TYPE_MODULE, THING_TYPE_GROUP).collect(Collectors.toSet()));
|
THING_TYPE_MODULE, THING_TYPE_GROUP);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
|
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.lcn.internal;
|
package org.openhab.binding.lcn.internal;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -25,8 +24,6 @@ import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
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.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
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 MODULE_NAME_PART_COUNT = 2;
|
||||||
private static final int DISCOVERY_TIMEOUT_SEC = 90;
|
private static final int DISCOVERY_TIMEOUT_SEC = 90;
|
||||||
private static final int ACK_TIMEOUT_MS = 1000;
|
private static final int ACK_TIMEOUT_MS = 1000;
|
||||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
|
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(LcnBindingConstants.THING_TYPE_MODULE);
|
||||||
.unmodifiableSet(Stream.of(LcnBindingConstants.THING_TYPE_MODULE).collect(Collectors.toSet()));
|
|
||||||
private @Nullable PckGatewayHandler bridgeHandler;
|
private @Nullable PckGatewayHandler bridgeHandler;
|
||||||
private final Map<LcnAddrMod, @Nullable Map<Integer, String>> moduleNames = new HashMap<>();
|
private final Map<LcnAddrMod, @Nullable Map<Integer, String>> moduleNames = new HashMap<>();
|
||||||
private final Map<LcnAddrMod, DiscoveryResultBuilder> discoveryResultBuilders = new ConcurrentHashMap<>();
|
private final Map<LcnAddrMod, DiscoveryResultBuilder> discoveryResultBuilders = new ConcurrentHashMap<>();
|
||||||
|
|
|
@ -157,7 +157,6 @@ public class LcnModuleHandler extends BaseThingHandler {
|
||||||
*
|
*
|
||||||
* @throws LcnException when the handler is not initialized
|
* @throws LcnException when the handler is not initialized
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("null")
|
|
||||||
protected void requestFirmwareVersionAndSerialNumberIfNotSet() throws LcnException {
|
protected void requestFirmwareVersionAndSerialNumberIfNotSet() throws LcnException {
|
||||||
String serialNumber = getThing().getProperties().get(Thing.PROPERTY_SERIAL_NUMBER);
|
String serialNumber = getThing().getProperties().get(Thing.PROPERTY_SERIAL_NUMBER);
|
||||||
if (serialNumber == null || serialNumber.isEmpty()) {
|
if (serialNumber == null || serialNumber.isEmpty()) {
|
||||||
|
@ -241,7 +240,6 @@ public class LcnModuleHandler extends BaseThingHandler {
|
||||||
*
|
*
|
||||||
* @param pck the message without line termination
|
* @param pck the message without line termination
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("null")
|
|
||||||
public void handleStatusMessage(String pck) {
|
public void handleStatusMessage(String pck) {
|
||||||
for (AbstractLcnModuleSubHandler handler : subHandlers.values()) {
|
for (AbstractLcnModuleSubHandler handler : subHandlers.values()) {
|
||||||
if (handler.tryParse(pck)) {
|
if (handler.tryParse(pck)) {
|
||||||
|
|
|
@ -55,7 +55,7 @@ public abstract class AbstractStateMachine<T extends AbstractStateMachine<T, U>,
|
||||||
|
|
||||||
state = newState;
|
state = newState;
|
||||||
|
|
||||||
state.startWorking();
|
newState.startWorking();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isStateActive(AbstractState<?, ?> otherState) {
|
protected boolean isStateActive(AbstractState<?, ?> otherState) {
|
||||||
|
|
|
@ -21,7 +21,13 @@ import java.nio.channels.Channel;
|
||||||
import java.nio.channels.CompletionHandler;
|
import java.nio.channels.CompletionHandler;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
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.BlockingQueue;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
@ -133,7 +139,10 @@ public class Connection {
|
||||||
public void onAck(LcnAddrMod addr, int code) {
|
public void onAck(LcnAddrMod addr, int code) {
|
||||||
synchronized (modData) {
|
synchronized (modData) {
|
||||||
if (modData.containsKey(addr)) {
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,6 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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.NonNullByDefault;
|
||||||
import org.openhab.binding.lcn.internal.LcnBindingConstants;
|
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 String PCHK_DISCOVERY_MULTICAST_ADDRESS = "234.5.6.7";
|
||||||
private static final int PCHK_DISCOVERY_PORT = 4220;
|
private static final int PCHK_DISCOVERY_PORT = 4220;
|
||||||
private static final int INTERFACE_TIMEOUT_SEC = 2;
|
private static final int INTERFACE_TIMEOUT_SEC = 2;
|
||||||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
|
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set
|
||||||
.unmodifiableSet(Stream.of(LcnBindingConstants.THING_TYPE_PCK_GATEWAY).collect(Collectors.toSet()));
|
.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>";
|
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 {
|
public LcnPchkDiscoveryService() throws IllegalArgumentException {
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.openhab.binding.lcn.internal.connection.ModInfo;
|
||||||
* @author Fabian Wolter - Initial contribution
|
* @author Fabian Wolter - Initial contribution
|
||||||
*/
|
*/
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
@MockitoSettings(strictness = Strictness.WARN)
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class AbstractTestLcnModuleSubHandler {
|
public class AbstractTestLcnModuleSubHandler {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue