From a44f7f17cce76f493ff9020cc7eae01d169b7a7f Mon Sep 17 00:00:00 2001 From: J-N-K Date: Mon, 7 Dec 2020 21:23:11 +0100 Subject: [PATCH] [exec] improve logging and documentation (#9282) * explain usage of input channel * fix wording Signed-off-by: Jan N. Klug --- bundles/org.openhab.binding.exec/README.md | 3 +++ .../binding/exec/internal/handler/ExecHandler.java | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.exec/README.md b/bundles/org.openhab.binding.exec/README.md index d19a5728d..9cfd3a267 100644 --- a/bundles/org.openhab.binding.exec/README.md +++ b/bundles/org.openhab.binding.exec/README.md @@ -67,6 +67,9 @@ All Things support the following channels: | run | Switch | Send ON to execute the command, the current state tells whether it is running or not | | lastexecution | DateTime | Time/Date the command was last executed, in yyyy-MM-dd'T'HH:mm:ss.SSSZ format | +**Attention:** Linking `input` to any other item type than `String` will result in erroneous behavior. +If needed, please use a rule to convert your item's state to a string. +Also note that only commands (e.g. `sendCommand`) to the `input` channel are recognized, updating the item's state will not work (e.g. `postUpdate`). ## Minimal Example diff --git a/bundles/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java b/bundles/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java index 57b7b050d..23b9425d5 100644 --- a/bundles/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java +++ b/bundles/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java @@ -21,6 +21,7 @@ import java.math.BigDecimal; import java.time.ZonedDateTime; import java.util.Arrays; import java.util.Calendar; +import java.util.Date; import java.util.IllegalFormatException; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -168,16 +169,17 @@ public class ExecHandler extends BaseThingHandler { // problem for external commands that generate a lot of output, but this will be dependent on the limits // of the underlying operating system. + Date date = Calendar.getInstance().getTime(); try { if (lastInput != null) { - commandLine = String.format(commandLine, Calendar.getInstance().getTime(), lastInput); + commandLine = String.format(commandLine, date, lastInput); } else { - commandLine = String.format(commandLine, Calendar.getInstance().getTime()); + commandLine = String.format(commandLine, date); } } catch (IllegalFormatException e) { logger.warn( - "An exception occurred while formatting the command line with the current time and input values : '{}'", - e.getMessage()); + "An exception occurred while formatting the command line '{}' with the current time '{}' and input value '{}': {}", + commandLine, date, lastInput, e.getMessage()); updateState(RUN, OnOffType.OFF); updateState(OUTPUT, new StringType(e.getMessage())); return;