Skip to content

Commit

Permalink
Added an example of the ScriptAction preset (#2228)
Browse files Browse the repository at this point in the history
* Added an example of the `ScriptAction` preset

Signed-off-by: Oleg Andreych <[email protected]>

* Changed brackets for some newly added anchors

Signed-off-by: Oleg Andreych <[email protected]>

* add JS and JRuby

Signed-off-by: Stefan Höhn <[email protected]>

* fix fences

Signed-off-by: Stefan Höhn <[email protected]>

* fix fences

Signed-off-by: Stefan Höhn <[email protected]>

* js indentation

Signed-off-by: Stefan Höhn <[email protected]>

* jruby indentation

Signed-off-by: Stefan Höhn <[email protected]>

---------

Signed-off-by: Oleg Andreych <[email protected]>
Signed-off-by: Stefan Höhn <[email protected]>
Co-authored-by: Stefan Höhn <[email protected]>
  • Loading branch information
OlegAndreych and stefan-hoehn authored May 30, 2024
1 parent 78acb0c commit 2cd2741
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions configuration/jsr223.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2cd2741

Please sign in to comment.