]> git.basschouten.com Git - openhab-addons.git/commitdiff
[exec] improve logging and documentation (#9282)
authorJ-N-K <J-N-K@users.noreply.github.com>
Mon, 7 Dec 2020 20:23:11 +0000 (21:23 +0100)
committerGitHub <noreply@github.com>
Mon, 7 Dec 2020 20:23:11 +0000 (12:23 -0800)
* explain usage of input channel
* fix wording

Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
bundles/org.openhab.binding.exec/README.md
bundles/org.openhab.binding.exec/src/main/java/org/openhab/binding/exec/internal/handler/ExecHandler.java

index d19a5728d4fdfb2b83befedd4c7857193375c4a6..9cfd3a2679941c0328e79b04f995fe30d4fee412 100644 (file)
@@ -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
 
index 57b7b050d255deec8bae763a23eb5472e0d5fb09..23b9425d58fd10129eb2eb4da09c7f2b73f4a127 100644 (file)
@@ -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;