Added an example of the `ScriptAction` preset (#2228)
* Added an example of the `ScriptAction` preset Signed-off-by: Oleg Andreych <kjiec4@gmail.com> * Changed brackets for some newly added anchors Signed-off-by: Oleg Andreych <kjiec4@gmail.com> * add JS and JRuby Signed-off-by: Stefan Höhn <mail@stefanhoehn.com> * fix fences Signed-off-by: Stefan Höhn <mail@stefanhoehn.com> * fix fences Signed-off-by: Stefan Höhn <mail@stefanhoehn.com> * js indentation Signed-off-by: Stefan Höhn <mail@stefanhoehn.com> * jruby indentation Signed-off-by: Stefan Höhn <mail@stefanhoehn.com> --------- Signed-off-by: Oleg Andreych <kjiec4@gmail.com> Signed-off-by: Stefan Höhn <mail@stefanhoehn.com> Co-authored-by: Stefan Höhn <mail@stefanhoehn.com>pull/2302/head
parent
78acb0c6b6
commit
2cd27418b0
configuration
|
@ -238,6 +238,8 @@ The `default` preset is preloaded, so it does not require importing.
|
|||
- [`RuleSimple`](#rulesimple-preset)
|
||||
- [`RuleSupport`](#rulesupport-preset)
|
||||
- [`RuleFactories`](#rulefactories-preset)
|
||||
- [`ScriptAction`](#scriptaction-preset)
|
||||
- [`cache`](#cache-preset)
|
||||
|
||||
#### Default Preset (`importPreset` not required)
|
||||
|
||||
|
@ -375,6 +377,60 @@ scriptExtension.importPreset("RuleFactories")
|
|||
| `ConditionHandlerFactory` | `org.openhab.core.automation.module.script.rulesupport.shared.factories.ScriptedConditionHandlerFactory` |
|
||||
| `TriggerHandlerFactory` | `org.openhab.core.automation.module.script.rulesupport.shared.factories.ScriptedTriggerHandlerFactory` |
|
||||
|
||||
#### `ScriptAction` Preset
|
||||
|
||||
This preset can be useful for scheduling asynchronous code execution with `org.openhab.core.automation.module.script.action.Timer`.
|
||||
|
||||
| Variable | Description |
|
||||
|-------------------|--------------------------------------------------------------------|
|
||||
| `scriptExecution` | `org.openhab.core.automation.module.script.action.ScriptExecution` |
|
||||
|
||||
:::: tabs
|
||||
|
||||
::: tab Groovy
|
||||
|
||||
```groovy
|
||||
scriptExtension.importPreset("ScriptAction")
|
||||
scriptExtension.importPreset("RuleSupport")
|
||||
scriptExtension.importPreset("RuleSimple")
|
||||
|
||||
scriptExecution.createTimer(ZonedDateTime.now(), () -> {
|
||||
org.slf4j.LoggerFactory.getLogger('Test logger').warn('Timer ran')
|
||||
})
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
::: tab JSScripting
|
||||
|
||||
```javascript
|
||||
actions.scriptExecution.createTimer(time.toZDT(1000), () => {
|
||||
console.info('Timer ran');
|
||||
})
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
::: tab DSL
|
||||
|
||||
```java
|
||||
createTimer(now.plusSeconds(1), [ |
|
||||
logInfo('Test logger', 'Timer ran')
|
||||
])
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
::: tab JRuby
|
||||
|
||||
```ruby
|
||||
after(1.second) do
|
||||
logger.info("Timer ran")
|
||||
end
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
#### `cache` Preset
|
||||
|
||||
The `cache` preset does not provide a default import and needs to be imported explicitly.
|
||||
|
|
Loading…
Reference in New Issue