Skip to content

Commit

Permalink
[modbus] Improve error message if data thing is configured for readin…
Browse files Browse the repository at this point in the history
…g but not connected to a polling bridge. (openhab#16054)

Signed-off-by: Markus Minichmayr <markus@minichmayr.net>
Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
  • Loading branch information
minichma authored and austvik committed Mar 27, 2024
1 parent 245825d commit 311b7b5
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ public synchronized void initialize() {
childOfEndpoint = true;
functionCode = null;
readRequest = null;
} else {
ModbusPollerThingHandler localPollerHandler = (ModbusPollerThingHandler) bridgeHandler;
} else if (bridgeHandler instanceof ModbusPollerThingHandler localPollerHandler) {
pollerHandler = localPollerHandler;
ModbusReadRequestBlueprint localReadRequest = localPollerHandler.getRequest();
if (localReadRequest == null) {
Expand All @@ -441,7 +440,12 @@ public synchronized void initialize() {
comms = localPollerHandler.getCommunicationInterface();
pollStart = localReadRequest.getReference();
childOfEndpoint = false;
} else {
String errmsg = String.format("Thing %s is connected to an unsupported type of bridge.",
getThing().getUID());
throw new ModbusConfigurationException(errmsg);
}

validateAndParseReadParameters(localConfig);
validateAndParseWriteParameters(localConfig);
validateMustReadOrWrite();
Expand Down Expand Up @@ -513,8 +517,8 @@ private void validateAndParseReadParameters(ModbusDataConfiguration config) thro
if (childOfEndpoint && readRequest == null) {
if (!readStartMissing || !readValueTypeMissing) {
String errmsg = String.format(
"Thing %s readStart=%s, and readValueType=%s were specified even though the data thing is child of endpoint (that is, write-only)!",
getThing().getUID(), config.getReadStart(), config.getReadValueType());
"Thing %s was configured for reading (readStart and/or readValueType specified) but the parent is not a polling bridge. Consider using a bridge of type 'Regular Poll'.",
getThing().getUID());
throw new ModbusConfigurationException(errmsg);
}
}
Expand Down

0 comments on commit 311b7b5

Please sign in to comment.