Skip to content

Commit b1f7fa7

Browse files
JSR223 mention lifecycle preset
1 parent 7ae2f0c commit b1f7fa7

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

configuration/jsr223.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ With `scriptExtension.get("automationManager")` the `automationManager` can be m
250250
- [`RuleFactories` Preset](#rulefactories-preset)
251251
- [`ScriptAction` Preset](#scriptaction-preset)
252252
- [`cache` Preset](#cache-preset)
253+
- [`lifecycle` Preset](#lifecycle-preset)
253254
- [`TriggerType` Objects (all JSR223 languages)](#triggertype-objects-all-jsr223-languages)
254255

255256
#### Default Preset (`importPreset` not required)
@@ -526,6 +527,44 @@ Both caches implement the `org.openhab.core.automation.module.script.rulesupport
526527
- `Object get(String key)`: Get the value for the given key from the cache. Non-existent keys return `null`.
527528
- `Object get(String key, Supplier<Object> supplier`: Get the value for the given key. If no value is present, add the value that is return from the `supplier`.
528529

530+
#### `lifecycle` Preset
531+
532+
It provides a mechanism to execute code, when the input file is deleted. Modifying a file deletes it and creates it again.
533+
534+
| Variable | Description |
535+
|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
536+
| `lifecycleTracker` | [`org.openhab.core.automation.module.script.LifecycleScriptExtensionProvider.LifecycleTracker`](https://www.openhab.org/javadoc/latest/org/openhab/core/automation/module/script/lifecyclescriptextensionprovider.lifecycletracker) |
537+
538+
:::: tabs
539+
540+
::: tab Groovy
541+
542+
```groovy
543+
scriptExtension.importPreset("lifecycle")
544+
545+
lifecycleTracker.addDisposeHook(new org.openhab.core.automation.module.script.LifecycleScriptExtensionProvider.Disposable() {
546+
public void dispose() {
547+
org.slf4j.LoggerFactory.getLogger('org.openhab.automation.example').info("Bye")
548+
}
549+
})
550+
```
551+
552+
:::
553+
554+
::: tab Nashorn&nbsp;JS
555+
556+
```js
557+
scriptExtension.importPreset("lifecycle")
558+
559+
lifecycleTracker.addDisposeHook(function() {
560+
Java.type('org.slf4j.LoggerFactory').getLogger("org.openhab.core.automation.examples").info("Bye")
561+
})
562+
```
563+
564+
:::
565+
566+
::::
567+
529568
### `TriggerType` Objects (all JSR223 languages)
530569

531570
The following trigger types are defined by openHAB (custom triggers can also be defined) and take the specified configuration parameters.

0 commit comments

Comments
 (0)