]> git.basschouten.com Git - openhab-addons.git/commitdiff
[jsscripting] Upgrade openhab-js to 2.0.4 (#13565)
authorFlorian Hotze <florianh_dev@icloud.com>
Tue, 18 Oct 2022 20:34:33 +0000 (22:34 +0200)
committerGitHub <noreply@github.com>
Tue, 18 Oct 2022 20:34:33 +0000 (22:34 +0200)
Fixes #13563.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
bundles/org.openhab.automation.jsscripting/README.md
bundles/org.openhab.automation.jsscripting/pom.xml

index 49ff42f40341cd9436ce399c1acd2e7d3a6a9402..12cee25054a3f6ba95cc49878fbdeb4e6ce201b7 100644 (file)
@@ -428,9 +428,6 @@ thing.setEnabled(false);
 The actions namespace allows interactions with openHAB actions.
 The following are a list of standard actions.
 
-Additional actions provided by user installed addons can be accessed using their common name on the actions name space
-(example:  `actions.Pushsafer.pushsafer(...)`)
-
 See [openhab-js : actions](https://openhab.github.io/openhab-js/actions.html) for full API documentation and additional actions.
 
 #### Audio Actions
@@ -492,7 +489,7 @@ Replace `<url>` with the request url.
 See [openhab-js : actions.ScriptExecution](https://openhab.github.io/openhab-js/actions.html#.ScriptExecution) for complete documentation.
 
 ```javascript
-let now = time.ZonedDateTime.now();
+var now = time.ZonedDateTime.now();
 
 // Function to run when the timer goes off.
 function timerOver () {
@@ -500,24 +497,72 @@ function timerOver () {
 }
 
 // Create the Timer.
-this.myTimer = actions.ScriptExecution.createTimer('My Timer', now.plusSeconds(10), timerOver);
+var myTimer = actions.ScriptExecution.createTimer('My Timer', now.plusSeconds(10), timerOver);
 
 // Cancel the timer.
-this.myTimer.cancel();
+myTimer.cancel();
 
 // Check whether the timer is active. Returns true if the timer is active and will be executed as scheduled.
-let active = this.myTimer.isActive();
+var active = myTimer.isActive();
 
 // Reschedule the timer.
-this.myTimer.reschedule(now.plusSeconds(5));
+myTimer.reschedule(now.plusSeconds(5));
+```
+
+If you need to pass some variables to the timer, there are two options to do so:
+
+**Use a function generator** <!-- markdownlint-disable-line MD036 -->
+
+This allows you to pass variables to the timer‘s callback function at timer creation.
+The variables can not be mutated after the timer function generator was used to create the function.
+
+```javascript
+var now = time.ZonedDateTime.now();
+
+// Function to run when the timer goes off.
+function timerOver (myVariable) {
+  return function () {
+    console.info('The timer is over. myVariable is: ' + myVariable);
+  }
+}
+
+// Create the Timer.
+var myTimer = actions.ScriptExecution.createTimer('My Timer', now.plusSeconds(10), timerOver('Hello world!'));
 ```
 
+**Pass a single variable to the timer** <!--markdownlint-disable-line MD036 -->
+
+This allows you to pass a single variable to the timer's callback function.
+Variables can be mutated (changed) after the timer has been created.
+Be aware that this can lead to unattended side effects, e.g. when you change the variable after timer creation, which can make debugging quite difficult!
+
+```javascript
+var now = time.ZonedDateTime.now();
+
+// Function to run when the timer goes off.
+function timerOver () {
+  console.info('The timer is over. myVariable is: ' + myVariable);
+}
+
+var myVariable = 'Hello world!';
+
+// Create the Timer.
+var myTimer = actions.ScriptExecution.createTimerWithArgument('My Timer', now.plusSeconds(10), myVariable, timerOver);
+
+myVariable = 'Hello mutation!';
+// When the timer runs, it will log "Hello mutation!" instead of "Hello world!"
+```
+
+You may also pass `this` to the timer to have access to all variables from the current context.
+
 #### Semantics Actions
 
 See [openhab-js : actions.Semantics](https://openhab.github.io/openhab-js/actions.html#.Semantics) for complete documentation.
 
 #### Things Actions
 
+It is possible to get the actions for a Thing using `actions.Things.getActions(bindingId, thingUid)`, e.g. `actions.Things.getActions('network', 'network:pingdevice:pc')`.
+
 See [openhab-js : actions.Things](https://openhab.github.io/openhab-js/actions.html#.Things) for complete documentation.
 
 #### Voice Actions
index 972bba650f0986cf5f58b5c3f2a521281f049288..699539f8c63340e5b3688e17aa8d4a4188ec27d9 100644 (file)
@@ -25,7 +25,7 @@
     <graal.version>21.3.0</graal.version>
     <asm.version>6.2.1</asm.version>
     <oh.version>${project.version}</oh.version>
-    <ohjs.version>openhab@2.0.3</ohjs.version>
+    <ohjs.version>openhab@2.0.4</ohjs.version>
   </properties>
 
   <build>