Skip to content

Commit 5a27a98

Browse files
JSR223 mention lifecycle preset
1 parent 7ae2f0c commit 5a27a98

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

configuration/jsr223.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ Note that prior to openHAB 3, script ordering was performed alphanumerically bas
236236

237237
To facilitate JSR223 scripting, several openHAB-related variables are automatically predefined within `ScriptExtension` presets.
238238
They can be loaded into the script context using `scriptExtension.importPreset(String preset)`, e.g. `scriptExtension.importPreset("RuleSimple")`.
239-
The `default` preset is preloaded, so it does not require importing.
239+
The `default` and `lifecycle` presets are preloaded, so they do not require importing.
240240
With `scriptExtension.get("automationManager")` the `automationManager` can be made available without loading a preset.
241241

242242
- [Overview](#overview)
@@ -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 (`importPreset` not required)](#lifecycle-preset-importpreset-not-required)
253254
- [`TriggerType` Objects (all JSR223 languages)](#triggertype-objects-all-jsr223-languages)
254255

255256
#### Default Preset (`importPreset` not required)
@@ -526,6 +527,40 @@ 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 (`importPreset` not required)
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+
lifecycleTracker.addDisposeHook(new org.openhab.core.automation.module.script.LifecycleScriptExtensionProvider.Disposable() {
544+
public void dispose() {
545+
org.slf4j.LoggerFactory.getLogger('org.openhab.automation.example').info("Bye")
546+
}
547+
})
548+
```
549+
550+
:::
551+
552+
::: tab Nashorn&nbsp;JS
553+
554+
```js
555+
lifecycleTracker.addDisposeHook(function() {
556+
Java.type('org.slf4j.LoggerFactory').getLogger("org.openhab.core.automation.examples").info("Bye")
557+
})
558+
```
559+
560+
:::
561+
562+
::::
563+
529564
### `TriggerType` Objects (all JSR223 languages)
530565

531566
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)