Skip to content

Commit 9f238e3

Browse files
holgerfriedrichandan67
authored andcommitted
[knx] Handle exceptions during initial read (openhab#12520)
fixes openhab#7239 Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
1 parent cb3610c commit 9f238e3

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/AbstractKNXClient.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.time.Duration;
1616
import java.util.Set;
17+
import java.util.concurrent.CancellationException;
1718
import java.util.concurrent.CopyOnWriteArraySet;
1819
import java.util.concurrent.LinkedBlockingQueue;
1920
import java.util.concurrent.ScheduledExecutorService;
@@ -291,6 +292,8 @@ private void readNextQueuedDatapoint() {
291292
logger.trace("Sending a Group Read Request telegram for {}", datapoint.getDatapoint().getMainAddress());
292293
processCommunicator.read(datapoint.getDatapoint());
293294
} catch (KNXException e) {
295+
// Note: KnxException does not cover KnxRuntimeException and subclasses KnxSecureException,
296+
// KnxIllegArgumentException
294297
if (datapoint.getRetries() < datapoint.getLimit()) {
295298
readDatapoints.add(datapoint);
296299
logger.debug("Could not read value for datapoint {}: {}. Going to retry.",
@@ -299,9 +302,15 @@ private void readNextQueuedDatapoint() {
299302
logger.warn("Giving up reading datapoint {}, the number of maximum retries ({}) is reached.",
300303
datapoint.getDatapoint().getMainAddress(), datapoint.getLimit());
301304
}
302-
} catch (InterruptedException e) {
305+
} catch (InterruptedException | CancellationException e) {
303306
logger.debug("Interrupted sending KNX read request");
304307
return;
308+
} catch (Exception e) {
309+
// Any other exception: Fail gracefully, i.e. notify user and continue reading next DP.
310+
// Not catching this would end the scheduled read for all DPs in case of an error.
311+
// Severity is warning as this is likely caused by a configuration error.
312+
logger.warn("Error reading datapoint {}: {}", datapoint.getDatapoint().getMainAddress(),
313+
e.getMessage());
305314
}
306315
}
307316
}

0 commit comments

Comments
 (0)