You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -532,6 +554,25 @@ Both caches implement the `org.openhab.core.automation.module.script.rulesupport
532
554
-`Object get(String key)`: Get the value for the given key from the cache. Non-existent keys return `null`.
533
555
-`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`.
The above instances provide implementations of the interfaces [`org.openhab.core.items.ItemRegistry`](https://www.openhab.org/javadoc/latest/org/openhab/core/items/itemregistry), [`org.openhab.core.items.MetadataRegistry`](https://www.openhab.org/javadoc/latest/org/openhab/core/items/metadataregistry) and [`org.openhab.core.thing.ThingRegistry`](https://www.openhab.org/javadoc/latest/org/openhab/core/thing/thingregistry) respectively.
569
+
The `itemChannelLinkRegistry` does not provide the same methods as the [`org.openhab.core.thing.link.ItemChannelLinkRegistry`](https://www.openhab.org/javadoc/latest/org/openhab/core/thing/link/itemchannellinkregistry) interface.
570
+
571
+
All instances from this preset have an `addPermanent(…)` method, in addition to `add(…)`.
572
+
With the `add(…)` method, elements added over the above instances are removed, when the script, which inserted the elements, is deleted or changed.
573
+
When `addPermanent(…)` is used, the inserted elements are … not removed.
574
+
`itemRegistry.addPermanent(…)`/`thingRegistry.addPermanent(…)` from this preset offer the same functionality as `itemRegistry.add(…)`/`things.add(…)` from the `default` preset.
575
+
535
576
### `TriggerType` Objects (all JSR223 languages)
536
577
537
578
The following trigger types are defined by openHAB (custom triggers can also be defined) and take the specified configuration parameters.
@@ -666,3 +707,131 @@ Read the JSR223 language specific documentation for examples of using these `Tri
666
707
|`startlevel`| The system `StartLevel`|
667
708
668
709
:::
710
+
711
+
### The `scriptLoaded` and `scriptUnloaded` functions
712
+
713
+
When a JSR223 script is created or changed and it contains the `scriptLoaded(String)` function, OpenHAB executes it, and passes as parameter the path of the loaded script.
714
+
Similarly, when a script is changed or deleted, and the script contained the `scriptUnloaded()` function, it is invoked.
715
+
`scriptLoaded(String)` is only executed when a script from the automation add-on directory, like `${OPENHAB_CONF}/automation/jsr223/`, is loaded.
716
+
It is not executed in transformations, UI rules with Inline Script action, UI scripts.
717
+
The [`lifecycleTracker`](#lifecycle-preset-importpreset-not-required) object and the `scriptUnloaded()` function serve similar purposes.
718
+
When a script is executed several times, on each execution it adds a Disposable, and then the script is changed, its `scriptUnloaded()` is executed once and each added Disposable is also `dispose()`d.
0 commit comments