openhab / openhab-core

Core framework of openHAB
https://www.openhab.org/
Eclipse Public License 2.0
915 stars 423 forks source link

[Automation - Feature Request] Verify system supports language used in scripted Actions/Conditions #541

Open 5iver opened 5 years ago

5iver commented 5 years ago

Javascript is included through the JDK, and #519 will add Jython and Groovy ScriptActions and ScriptConditions. When Templates are imported, they could contain scripted Modules for languages that the system does not support. A verification check should be added to confirm the language is supported, reject the import if it is not, and notify the user. At the very least, keep rule UNINITIALIZED (which I think is the current functionality... haven't tested). Once we have bundles for JSR223 languages, we could install the bundles for supported scripted Modules.

After more thought, the scope is more than just Templates, since one could potentially manually write a JSON rule with a scripted Action/Condition.

And a side note, since I don't have a good place to put it yet... scripted Actions created through a JSR223 script have a a ModuleType of jsr223.ScriptedAction, but one created in Paper UI is script.ScriptAction (easily viewed in RestDocs).

J-N-K commented 5 months ago

I checked what it takes to implement it. And there is one issue: A rule can contain more than one action (e.g. a script and serveral item commands). Keeping the rule uninitialized when the script engine is missing might be confusing, because other actions would also stop. Additionally, the script engine could be loaded after the rule was parsed. A faile execution is logged, so my proposal would be to close this issue.

rkoshak commented 5 months ago

I think it would be useful if at the time of installation warnings are printed to the log if the template uses a script type for which a suitable add-on is not currently installed.

I agree that checking on every load isn't necessarily useful for the reasons you mention and disabling the rule could be confusing. But a check and warning in the logs during initial parsing and installation of the template would avoid those limitations since if the user is installing the template OH must already be up and operational.

stale[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.