[knx] Fix SAT warnings (#14052)

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich 2022-12-24 12:11:28 +01:00 committed by GitHub
parent f619798f81
commit 0357049f9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 30 deletions

View File

@ -223,9 +223,7 @@ It is created by the ETS tool and cannot be changed via the ETS user interface.
For _Secure tunneling_ with a Secure IP Interface (or a router in tunneling mode), more parameters are required. For _Secure tunneling_ with a Secure IP Interface (or a router in tunneling mode), more parameters are required.
A unique device authentication key, and a specific tunnel identifier and password need to be available. A unique device authentication key, and a specific tunnel identifier and password need to be available.
- All information can be looked up in ETS and provided separately: `tunnelDeviceAuthentication`, `tunnelUserPassword`. - All information can be looked up in ETS and provided separately: `tunnelDeviceAuthentication`, `tunnelUserPassword`. `tunnelUserId` is a number which is not directly visible in ETS, but can be looked up in keyring export or deduced (typically 2 for the first tunnel of a device, 3 for the second one, ...). `tunnelUserPasswort` is set in ETS in the properties of the tunnel (below the IP interface you will see the different tunnels listed) denoted as "Password". `tunnelDeviceAuthentication` is set in the properties of the IP interface itself, check for a tab "IP" and a description "Authentication Code".
`tunnelUserId` is a number which is not directly visible in ETS, but can be looked up in keyring export or deduced (typically 2 for the first tunnel of a device, 3 for the second one, ...).
`tunnelUserPasswort` is set in ETS in the properties of the tunnel (below the IP interface you will see the different tunnels listed) denoted as "Password". `tunnelDeviceAuthentication` is set in the properties of the IP interface itself, check for a tab "IP" and a description "Authentication Code".
### KNX Data Secure ### KNX Data Secure

View File

@ -12,6 +12,7 @@
*/ */
package org.openhab.binding.knx.internal.channel; package org.openhab.binding.knx.internal.channel;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.knx.internal.client.OutboundSpec; import org.openhab.binding.knx.internal.client.OutboundSpec;
import org.openhab.core.types.Type; import org.openhab.core.types.Type;
@ -25,6 +26,7 @@ import tuwien.auto.calimero.KNXFormatException;
* @author Simon Kaufmann - initial contribution and API. * @author Simon Kaufmann - initial contribution and API.
* *
*/ */
@NonNullByDefault
public class WriteSpecImpl extends AbstractSpec implements OutboundSpec { public class WriteSpecImpl extends AbstractSpec implements OutboundSpec {
private final Type type; private final Type type;

View File

@ -12,6 +12,9 @@
*/ */
package org.openhab.binding.knx.internal.client; package org.openhab.binding.knx.internal.client;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import tuwien.auto.calimero.datapoint.Datapoint; import tuwien.auto.calimero.datapoint.Datapoint;
/** /**
@ -19,6 +22,7 @@ import tuwien.auto.calimero.datapoint.Datapoint;
* *
* @author Karel Goderis - Initial contribution * @author Karel Goderis - Initial contribution
*/ */
@NonNullByDefault
public class ReadDatapoint { public class ReadDatapoint {
private final Datapoint datapoint; private final Datapoint datapoint;
@ -56,7 +60,7 @@ public class ReadDatapoint {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@ -66,14 +70,8 @@ public class ReadDatapoint {
if (getClass() != obj.getClass()) { if (getClass() != obj.getClass()) {
return false; return false;
} }
@Nullable
ReadDatapoint other = (ReadDatapoint) obj; ReadDatapoint other = (ReadDatapoint) obj;
if (datapoint == null) { return datapoint.getMainAddress().equals(other.datapoint.getMainAddress());
if (other.datapoint != null) {
return false;
}
} else if (!datapoint.getMainAddress().equals(other.datapoint.getMainAddress())) {
return false;
}
return true;
} }
} }

View File

@ -26,6 +26,8 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.knx.internal.KNXTypeMapper; import org.openhab.binding.knx.internal.KNXTypeMapper;
import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.DecimalType;
@ -84,11 +86,12 @@ import tuwien.auto.calimero.dptxlator.TranslatorTypes;
* If for a 'MainType' there is currently no specific mapping registered, * If for a 'MainType' there is currently no specific mapping registered,
* you can find a commented example line, with it's correct 'DPTXlator' class. * you can find a commented example line, with it's correct 'DPTXlator' class.
* *
* @author Kai Kreuzer * @author Kai Kreuzer - initial contribution
* @author Volker Daube * @author Volker Daube - improvements
* @author Jan N. Klug * @author Jan N. Klug - improvements
* @author Helmut Lehmeyer - Java8, generic DPT Mapper * @author Helmut Lehmeyer - Java8, generic DPT Mapper
*/ */
@NonNullByDefault
@Component @Component
public class KNXCoreTypeMapper implements KNXTypeMapper { public class KNXCoreTypeMapper implements KNXTypeMapper {
@ -735,7 +738,7 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
} }
@Override @Override
public String toDPTValue(Type type, String dptID) { public @Nullable String toDPTValue(Type type, @Nullable String dptID) {
DPT dpt; DPT dpt;
int mainNumber = getMainNumber(dptID); int mainNumber = getMainNumber(dptID);
if (mainNumber == -1) { if (mainNumber == -1) {
@ -838,7 +841,7 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
} }
@Override @Override
public Type toType(Datapoint datapoint, byte[] data) { public @Nullable Type toType(Datapoint datapoint, byte[] data) {
try { try {
DPTXlator translator = TranslatorTypes.createTranslator(datapoint.getMainNumber(), datapoint.getDPT()); DPTXlator translator = TranslatorTypes.createTranslator(datapoint.getMainNumber(), datapoint.getDPT());
translator.setData(data); translator.setData(data);
@ -996,7 +999,7 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
if (typeClass.equals(DateTimeType.class)) { if (typeClass.equals(DateTimeType.class)) {
String date = formatDateTime(value, datapoint.getDPT()); String date = formatDateTime(value, datapoint.getDPT());
if ((date == null) || (date.isEmpty())) { if (date.isEmpty()) {
logger.debug("toType: KNX clock msg ignored: date object null or empty {}.", date); logger.debug("toType: KNX clock msg ignored: date object null or empty {}.", date);
return null; return null;
} else { } else {
@ -1033,7 +1036,8 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
* @return the openHAB type (command or state) class or {@code null} if the datapoint type id is not supported. * @return the openHAB type (command or state) class or {@code null} if the datapoint type id is not supported.
*/ */
@Override @Override
public Class<? extends Type> toTypeClass(String dptId) { public @Nullable Class<? extends Type> toTypeClass(@Nullable String dptId) {
@Nullable
Class<? extends Type> ohClass = dptTypeMap.get(dptId); Class<? extends Type> ohClass = dptTypeMap.get(dptId);
if (ohClass == null) { if (ohClass == null) {
int mainNumber = getMainNumber(dptId); int mainNumber = getMainNumber(dptId);
@ -1052,7 +1056,7 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
* @param typeClass the openHAB type class * @param typeClass the openHAB type class
* @return the datapoint type id * @return the datapoint type id
*/ */
public String toDPTid(Class<? extends Type> typeClass) { public @Nullable String toDPTid(Class<? extends Type> typeClass) {
return defaultDptMap.get(typeClass); return defaultDptMap.get(typeClass);
} }
@ -1114,7 +1118,7 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
* @throws IllegalArgumentException if none of the datapoint types DPT_DATE or * @throws IllegalArgumentException if none of the datapoint types DPT_DATE or
* DPT_TIMEOFDAY has been used. * DPT_TIMEOFDAY has been used.
*/ */
private static String formatDateTime(DateTimeType dateType, String dpt) { private static String formatDateTime(DateTimeType dateType, @Nullable String dpt) {
if (DPTXlatorDate.DPT_DATE.getID().equals(dpt)) { if (DPTXlatorDate.DPT_DATE.getID().equals(dpt)) {
return dateType.format("%tF"); return dateType.format("%tF");
} else if (DPTXlatorTime.DPT_TIMEOFDAY.getID().equals(dpt)) { } else if (DPTXlatorTime.DPT_TIMEOFDAY.getID().equals(dpt)) {
@ -1132,7 +1136,7 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
* @param dptID String with DPT ID * @param dptID String with DPT ID
* @return sub number or -1 * @return sub number or -1
*/ */
private int getSubNumber(String dptID) { private int getSubNumber(@Nullable String dptID) {
int result = -1; int result = -1;
if (dptID == null) { if (dptID == null) {
throw new IllegalArgumentException("Parameter dptID cannot be null"); throw new IllegalArgumentException("Parameter dptID cannot be null");
@ -1159,7 +1163,7 @@ public class KNXCoreTypeMapper implements KNXTypeMapper {
* @param dptID String with DPT ID * @param dptID String with DPT ID
* @return main number or -1 * @return main number or -1
*/ */
private int getMainNumber(String dptID) { private int getMainNumber(@Nullable String dptID) {
int result = -1; int result = -1;
if (dptID == null) { if (dptID == null) {
throw new IllegalArgumentException("Parameter dptID cannot be null"); throw new IllegalArgumentException("Parameter dptID cannot be null");

View File

@ -17,6 +17,8 @@ import static org.openhab.binding.knx.internal.KNXBindingConstants.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.knx.internal.handler.DeviceThingHandler; import org.openhab.binding.knx.internal.handler.DeviceThingHandler;
import org.openhab.binding.knx.internal.handler.IPBridgeThingHandler; import org.openhab.binding.knx.internal.handler.IPBridgeThingHandler;
import org.openhab.binding.knx.internal.handler.SerialBridgeThingHandler; import org.openhab.binding.knx.internal.handler.SerialBridgeThingHandler;
@ -42,12 +44,14 @@ import org.osgi.service.component.annotations.Reference;
* *
* @author Simon Kaufmann - Initial contribution and API * @author Simon Kaufmann - Initial contribution and API
*/ */
@NonNullByDefault
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.knx") @Component(service = ThingHandlerFactory.class, configurationPid = "binding.knx")
public class KNXHandlerFactory extends BaseThingHandlerFactory { public class KNXHandlerFactory extends BaseThingHandlerFactory {
public static final Collection<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Arrays.asList(THING_TYPE_DEVICE, public static final Collection<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Arrays.asList(THING_TYPE_DEVICE,
THING_TYPE_IP_BRIDGE, THING_TYPE_SERIAL_BRIDGE); THING_TYPE_IP_BRIDGE, THING_TYPE_SERIAL_BRIDGE);
@Nullable
private NetworkAddressService networkAddressService; private NetworkAddressService networkAddressService;
@Activate @Activate
@ -62,8 +66,8 @@ public class KNXHandlerFactory extends BaseThingHandlerFactory {
} }
@Override @Override
public Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID, public @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration,
ThingUID bridgeUID) { @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) {
if (THING_TYPE_IP_BRIDGE.equals(thingTypeUID)) { if (THING_TYPE_IP_BRIDGE.equals(thingTypeUID)) {
ThingUID ipBridgeUID = getIPBridgeThingUID(thingTypeUID, thingUID, configuration); ThingUID ipBridgeUID = getIPBridgeThingUID(thingTypeUID, thingUID, configuration);
return super.createThing(thingTypeUID, configuration, ipBridgeUID, null); return super.createThing(thingTypeUID, configuration, ipBridgeUID, null);
@ -79,7 +83,7 @@ public class KNXHandlerFactory extends BaseThingHandlerFactory {
} }
@Override @Override
protected ThingHandler createHandler(Thing thing) { protected @Nullable ThingHandler createHandler(Thing thing) {
if (thing.getThingTypeUID().equals(THING_TYPE_IP_BRIDGE)) { if (thing.getThingTypeUID().equals(THING_TYPE_IP_BRIDGE)) {
return new IPBridgeThingHandler((Bridge) thing, networkAddressService); return new IPBridgeThingHandler((Bridge) thing, networkAddressService);
} else if (thing.getThingTypeUID().equals(THING_TYPE_SERIAL_BRIDGE)) { } else if (thing.getThingTypeUID().equals(THING_TYPE_SERIAL_BRIDGE)) {
@ -90,7 +94,8 @@ public class KNXHandlerFactory extends BaseThingHandlerFactory {
return null; return null;
} }
private ThingUID getIPBridgeThingUID(ThingTypeUID thingTypeUID, ThingUID thingUID, Configuration configuration) { private ThingUID getIPBridgeThingUID(ThingTypeUID thingTypeUID, @Nullable ThingUID thingUID,
Configuration configuration) {
if (thingUID != null) { if (thingUID != null) {
return thingUID; return thingUID;
} }
@ -98,7 +103,7 @@ public class KNXHandlerFactory extends BaseThingHandlerFactory {
return new ThingUID(thingTypeUID, ipAddress); return new ThingUID(thingTypeUID, ipAddress);
} }
private ThingUID getSerialBridgeThingUID(ThingTypeUID thingTypeUID, ThingUID thingUID, private ThingUID getSerialBridgeThingUID(ThingTypeUID thingTypeUID, @Nullable ThingUID thingUID,
Configuration configuration) { Configuration configuration) {
if (thingUID != null) { if (thingUID != null) {
return thingUID; return thingUID;

View File

@ -53,9 +53,9 @@ public class IPBridgeThingHandler extends KNXBridgeBaseThingHandler {
private final Logger logger = LoggerFactory.getLogger(IPBridgeThingHandler.class); private final Logger logger = LoggerFactory.getLogger(IPBridgeThingHandler.class);
private @Nullable IPClient client = null; private @Nullable IPClient client = null;
private final NetworkAddressService networkAddressService; private @Nullable final NetworkAddressService networkAddressService;
public IPBridgeThingHandler(Bridge bridge, NetworkAddressService networkAddressService) { public IPBridgeThingHandler(Bridge bridge, @Nullable NetworkAddressService networkAddressService) {
super(bridge); super(bridge);
this.networkAddressService = networkAddressService; this.networkAddressService = networkAddressService;
} }
@ -171,6 +171,11 @@ public class IPBridgeThingHandler extends KNXBridgeBaseThingHandler {
if (!config.getLocalIp().isEmpty()) { if (!config.getLocalIp().isEmpty()) {
localEndPoint = new InetSocketAddress(config.getLocalIp(), 0); localEndPoint = new InetSocketAddress(config.getLocalIp(), 0);
} else { } else {
if (networkAddressService == null) {
logger.debug("NetworkAddressService not available, cannot create bridge {}", thing.getUID());
updateStatus(ThingStatus.OFFLINE);
return;
}
localEndPoint = new InetSocketAddress(networkAddressService.getPrimaryIpv4HostAddress(), 0); localEndPoint = new InetSocketAddress(networkAddressService.getPrimaryIpv4HostAddress(), 0);
} }