Skip to content
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

JSR223: Include automationManager in the Default preset #4368

Open
dilyanpalauzov opened this issue Sep 1, 2024 · 7 comments
Open

JSR223: Include automationManager in the Default preset #4368

dilyanpalauzov opened this issue Sep 1, 2024 · 7 comments
Labels
enhancement An enhancement or new feature of the Core

Comments

@dilyanpalauzov
Copy link
Contributor

When writing rules in JSR 223, one ultimately has to access automationManager to do something useful. The presets - Default, RuleSimple, RuleSupport, RuleFactories, ScriptAction and cache - provide some implicit imports and objects (variables). The latter objects enable connecting the JSR223 code with the OH internals and installing some meaningful automation.

As the only way described at https://www.openhab.org/docs/configuration/jsr223.html to install a rule is to use automationManager and thus to import the RuleSupport preset, this preset has always to be included explicitly by the caller. The other items from the preset are not strictly necessary, as they can be obtained by imports. (And the imports are required to move as much code in Groovy as possible under the TypeChecked and CompileStatic annotations).

@dilyanpalauzov dilyanpalauzov added the enhancement An enhancement or new feature of the Core label Sep 1, 2024
@jimtng
Copy link
Contributor

jimtng commented Sep 1, 2024

You can obtain automationManager through scriptExtension.get("automationManager"). scriptExtension is injected by default, without having to import any presets.

@dilyanpalauzov
Copy link
Contributor Author

Yes, this is indeed the case. But this is not documented at https://www.openhab.org/docs/configuration/jsr223.html, so scriptExtension.importPreset("RuleSupport") is always called in order to get access to automationManager.

@lolodomo
Copy link
Contributor

You are welcome to improve the existing documentation.

@dilyanpalauzov
Copy link
Contributor Author

You are welcome to improve the existing documentation.

When I try to improve the existing documentation, changes can get stuck: https://github.com/openhab/openhab-docs/pulls/dilyanpalauzov

@lolodomo
Copy link
Contributor

Try to ping @florian-h05

@florian-h05
Copy link
Contributor

I don't think automationManager belongs into the Default preset, as it is related to supporting rule creation.
The possibility to statically import other members of the RuleSupport preset should not change that relation.

I would suggest to improve the docs as @jimtng suggested and ping me, so I can take care the PR gets reviewed and merged.

@dilyanpalauzov
Copy link
Contributor Author

I don't think automationManager belongs into the Default preset, as it is related to supporting rule creation.

Yes, if no rule creation is going to happen, why will somebody in first place use the JSR223 extension mechanism? JSR223 is used to create and activate rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
None yet
Development

No branches or pull requests

4 participants