Openhab 2 jython support

Hello @steve1,
is it this?

Thanks.That definitely looks like it could be the cause of the problem. If I can get a clean build with the latest code I’ll try to do some experimentation.

Not sure I understand you right.
Do you know this mini wiki for automation? https://github.com/eclipse/smarthome/wiki/Scripted-Rule-Support

I’ll send you the newest bundles, but these can be found in nightly builds too.

I meant I was going to try to step through code in the IDE debugger, but I need an Eclipse project that will build cleanly. Do you know how to force code generation for the xtext files? I’m seeing some build errors that look like code might need to be regenerated.

The name “scripted_XXXXX” error comes from this change:

That has to be changed, but I’m currently not at my development PC. I will open an issue for that

Thanks @smerschjo, ftr: Jsr223 Rule-Id Generation · Issue #3528 · eclipse-archived/smarthome · GitHub

Issue is fixed and I have just built a new distro (#930) - it works smoothly with at least a js example:

09:21:24.401 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'example.js'
09:21:25.059 [INFO ] [smarthome.event.RuleAddedEvent      ] - Rule 'rule_1' has been added.
09:21:25.062 [INFO ] [smarthome.event.RuleStatusInfoEvent ] - rule_1 updated: INITIALIZING
09:21:25.096 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'example2.js'
09:21:25.098 [INFO ] [smarthome.event.RuleStatusInfoEvent ] - rule_1 updated: IDLE
09:21:25.175 [INFO ] [smarthome.event.RuleAddedEvent      ] - Rule 'rule_2' has been added.
09:21:25.175 [INFO ] [smarthome.event.RuleStatusInfoEvent ] - rule_2 updated: INITIALIZING
09:21:25.181 [INFO ] [smarthome.event.RuleStatusInfoEvent ] - rule_2 updated: IDLE

So please go ahead with testing and writing docs for this feature!

1 Like

It looks like the file loading (file watcher?) issues are still there. I see my test script loaded once but it is not reloaded when I update it. Helmut thought it might be related to the issue he referenced earlier in this thread.

I’ve done some more testing and it seems like the script reloading is actually working so I’ll start generating some examples and related documentation. Thanks, Kai!

2 Likes

@smerschjo It seems like the scriptUnload functionality is not working correctly. The scriptUnloaded callback is not invoked when a script is removed. Also, when an existing script is modified and saved, the scriptLoaded callback is invoked but the scriptUnloaded callback is not. This is the behavior reported by other users earlier in this topic.

AFAICT, the ScriptEngineManager.removeEngine is trying to look up the scriptIdentifier in the loadedScriptEngineInstances. However, the key in loadedScriptEngineInstances map is a simple file name (‘test.py’, in my case) and the scriptIdentifier is a URI with the absolute path of the file. Since the rule engine is not found, it is not removed or unloaded.

@smerschjo I’ve fixed the ScriptEngineManager issue in my dev workspace but I’ve run into another problem. The SimpleRule class uses the default Rule constructor which does not set the UID. When a rule is being removed during script unloading, the null UID is used to build an event topic and this causes an exception. I modified my SimpleRule code to generate a UID and pass it to the Rule base class constructor. This has fixed the issue but I don’t know if that’s the preferred solution.

Thanks for opening issue tickets for it. I will have a look at them. I think it would not be a good idea to generate the uid in the SimpleRule class. I will figure something out.