]> git.basschouten.com Git - openhab-addons.git/commitdiff
[knx] FT12: List available serial ports if port cannot be opened (#12942)
authorHolger Friedrich <holgerfriedrich@users.noreply.github.com>
Sun, 19 Jun 2022 12:50:35 +0000 (14:50 +0200)
committerGitHub <noreply@github.com>
Sun, 19 Jun 2022 12:50:35 +0000 (14:50 +0200)
Fixes a regression introduced by upgrading Calimero library to 2.5.

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/SerialClient.java

index 2a49d5d2dbaf38fbe3e0b0abd4423ea8c28887b3..ce1d0c34233229db52e3027b82942d5d3d77dd0e 100644 (file)
@@ -36,6 +36,8 @@ import tuwien.auto.calimero.link.medium.TPSettings;
 @NonNullByDefault
 public class SerialClient extends AbstractKNXClient {
 
+    private static final String CALIMERO_ERROR_CANNOT_OPEN_PORT = "failed to open serial port";
+
     private final Logger logger = LoggerFactory.getLogger(SerialClient.class);
 
     private final String serialPort;
@@ -69,7 +71,8 @@ public class SerialClient extends AbstractKNXClient {
                     e);
         } catch (KNXException e) {
             final String msg = e.getMessage();
-            if ((msg != null) && (msg.startsWith("can not open serial port"))) {
+            // TODO add a test for this string match; error message might change in later version of Calimero library
+            if ((msg != null) && (msg.startsWith(CALIMERO_ERROR_CANNOT_OPEN_PORT))) {
                 StringBuilder sb = new StringBuilder("Available ports are:\n");
                 Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
                 while (portList.hasMoreElements()) {