]> git.basschouten.com Git - openhab-addons.git/commitdiff
[knx] Handle exceptions during initial read (#12520)
authorHolger Friedrich <holgerfriedrich@users.noreply.github.com>
Fri, 8 Apr 2022 20:25:14 +0000 (22:25 +0200)
committerGitHub <noreply@github.com>
Fri, 8 Apr 2022 20:25:14 +0000 (22:25 +0200)
fixes #7239

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

index 88e3386c8dd6d61b43910dcab9c1f98d8b0c2c5c..ecc905fd68e0561de3442e6b8e019617cfb24217 100644 (file)
@@ -14,6 +14,7 @@ package org.openhab.binding.knx.internal.client;
 
 import java.time.Duration;
 import java.util.Set;
+import java.util.concurrent.CancellationException;
 import java.util.concurrent.CopyOnWriteArraySet;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ScheduledExecutorService;
@@ -291,6 +292,8 @@ public abstract class AbstractKNXClient implements NetworkLinkListener, KNXClien
                 logger.trace("Sending a Group Read Request telegram for {}", datapoint.getDatapoint().getMainAddress());
                 processCommunicator.read(datapoint.getDatapoint());
             } catch (KNXException e) {
+                // Note: KnxException does not cover KnxRuntimeException and subclasses KnxSecureException,
+                // KnxIllegArgumentException
                 if (datapoint.getRetries() < datapoint.getLimit()) {
                     readDatapoints.add(datapoint);
                     logger.debug("Could not read value for datapoint {}: {}. Going to retry.",
@@ -299,9 +302,15 @@ public abstract class AbstractKNXClient implements NetworkLinkListener, KNXClien
                     logger.warn("Giving up reading datapoint {}, the number of maximum retries ({}) is reached.",
                             datapoint.getDatapoint().getMainAddress(), datapoint.getLimit());
                 }
-            } catch (InterruptedException e) {
+            } catch (InterruptedException | CancellationException e) {
                 logger.debug("Interrupted sending KNX read request");
                 return;
+            } catch (Exception e) {
+                // Any other exception: Fail gracefully, i.e. notify user and continue reading next DP.
+                // Not catching this would end the scheduled read for all DPs in case of an error.
+                // Severity is warning as this is likely caused by a configuration error.
+                logger.warn("Error reading datapoint {}: {}", datapoint.getDatapoint().getMainAddress(),
+                        e.getMessage());
             }
         }
     }