-
-
Notifications
You must be signed in to change notification settings - Fork 724
JSR223: Add lifecycle, media, provider presets & scriptLoaded, scriptUnloaded functions #2567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1c96144 to
746786d
Compare
✅ Thanks for your pull request to the openHAB documentation! The result can be previewed at the URL below (this comment and the preview will be updated if you add more commits).Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
746786d to
92385ef
Compare
✅ Thanks for your pull request to the openHAB documentation! The result can be previewed at the URL below (this comment and the preview will be updated if you add more commits).Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Thanks for your pull request to the openHAB documentation! The result can be previewed at the URL below (this comment and the preview will be updated if you add more commits).
To edit notification comments on pull requests, go to your Netlify project configuration. |
a09886c to
b1f7fa7
Compare
|
Now includes Nashorn example. |
|
The current proposed change is correct, but only part of the truth. My understanding is that if a class public List<String> getDefaultPresets() {
List<String> defaultPresets = new ArrayList<>();
for (ScriptExtensionProvider provider : scriptExtensionProviders) {
defaultPresets.addAll(provider.getDefaultPresets());
}
return defaultPresets;
}That is, the |
5a27a98 to
a13b13b
Compare
|
Besides, one of the presets, which is loaded without |
7d1cde9 to
1923155
Compare
|
I added also the |
1923155 to
3e8ae1f
Compare
stefan-hoehn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@florian-h05 please check the content.
configuration/jsr223.md
Outdated
|
|
||
| #### `lifecycle` Preset (`importPreset` not required) | ||
|
|
||
| It provides a mechanism to execute code, when the input file is deleted. Modifying a file deletes it and creates it again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2nd sentence has be in the next line. (make sure the first sentence doesn't have a trailing space then.
a23e4f7 to
cadce01
Compare
cadce01 to
bddb4cd
Compare
|
I have described also the |
88f694c to
c2d6325
Compare
bf4b509 to
a9b1964
Compare
f27cdec to
a5603b2
Compare
…d scriptUnloaded functions
a5603b2 to
d68ff70
Compare
Signed-off-by: Florian Hotze <[email protected]>
florian-h05
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I've reworded a few things during review.
Signed-off-by: Florian Hotze <[email protected]>
Signed-off-by: Florian Hotze <[email protected]>
| All instances from this preset have an `addPermanent(...)` method, in addition to `add(...)`. | ||
| With the `add(...)` method, elements added over the above instances are removed, when the script, which inserted the elements, is deleted or changed. | ||
| When `addPermanent(...)` is used, the inserted elements `...` are not removed. | ||
| `itemRegistry.addPermanent(...)`/`metadataRegistry.addPermanent(...)`/`thingRegistry.addPermanent(...)` from this preset offer the same functionality as `itemRegistry.add(...)`/`metadataRegistry.add(...)`/`things.add(...)` from the `default` preset. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default preset is implemented in https://github.com/openhab/openhab-core/blob/main/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/defaultscope/DefaultScriptScopeProvider.java. It does not have metadataRegistry.
| When a script file is loaded, the `scriptLoaded(String)` function is invoked if it is defined. | ||
| The path of the script file will be passed as parameter. | ||
| Similarly, when a script file is unloaded, the `scriptUnloaded()` function is invoked if it is defined. | ||
| Note that `scriptLoaded(String)` and `scriptUnloaded()` are only executed for script files - not Script Actions and Script conditions of rules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original text suggests that for transformations (file in etc/openhab/transform) scriptUnloaded() is executed, but scriptLoaded(String) is not executed. After the changes this information is lost.
| Similarly, when a script file is unloaded, the `scriptUnloaded()` function is invoked if it is defined. | ||
| Note that `scriptLoaded(String)` and `scriptUnloaded()` are only executed for script files - not Script Actions and Script conditions of rules. | ||
|
|
||
| [`lifecycleTracker`](#lifecycle-preset-importpreset-not-required)'s `addDisposeHook(Disposable)` and the `scriptUnloaded()` function serve similar purposes, but it is recommended to use `addDisposeHook(Disposable)` as it's functionality is not limited to script files only. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
”it`s" → “its”.
Why was this removed:
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 alsodispose()d.
This is not what I meant:
The
lifecyleTrackeralso supports adding multiple dispose hooks, contrary toscriptUnloaded()that can only be defined once.
I meant that defining once scriptUnloaded() and one Disposable in a script, then executing the script several times, then modifying the script, will execute scriptUnloaded once, and the Disposable many times. (as many times as the script was executed, provided that each execution created unconditinonally a new Disposable - this can be tested in transformations)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should a script be executed several times? A transformation can be, but a script not. Since scriptUnloaded is not available in transformations that information provides no benefit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I wrote that tests I believe I created transformations with scriptUnloaded(), scriptLoaded(String) and lifecycleTracker. scriptLoaded(String) was not executed, scriptUnloaded() and the Disposable were executed. I mean transformations with a file under etc/openhab/transform/. So an openHAB-Groovy-filebased-Transformation is a Groovy-Script and it can be executed several times.
| `itemRegistry.addPermanent(…)`/`thingRegistry.addPermanent(…)` from this preset offer the same functionality as `itemRegistry.add(…)`/`things.add(…)` from the `default` preset. | ||
| All instances from this preset have an `addPermanent(...)` method, in addition to `add(...)`. | ||
| With the `add(...)` method, elements added over the above instances are removed, when the script, which inserted the elements, is deleted or changed. | ||
| When `addPermanent(...)` is used, the inserted elements `...` are not removed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second ellipsis I used on that line was supposed to “mark a pause in speech” - as allowed by https://en.wikipedia.org/wiki/Ellipsis , not to cite the parameters introduced by the first ellipsis.
| ::: tab Python | ||
|
|
||
| When the setting “Use scope and import wrapper” is on, the `scope` module is enabled: | ||
| When the setting "Use scope and import wrapper" is enabled, the `scope` module is enabled: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This repeats “enabled” twice in the same sentence.
I add example only for Groovy, as I do know how to use it in the other automation add-ons. Besides, the other rule engines provide other ways for the same functionality:
script_unloadedin JRuby, and for others I do not know if the functionality is from openhab-core, or from the add-on.