Advice on starting with Jython and NGRE

I am using OpenHAB 2.5.5 on my raspberry piv3B. I am not a Java programmer but I managed to implement in the DSL several rules to manage fritz!DECT and Sonoff Switches to implement a load shredding application.
Thanks to the Design Patterns by Rlkoshak I managed to increase the flexibility of my application: this allowed to manage more switches, but the maintainability is poor. Rules are rather long and difficult to read after some time so that the changes that I introduce generate unwanted side-effects.

Based on the shortcomings that I experienced, I am re-designing my application but I would like to implement it in a more future-proof and compact way, taking advantage of new functionalities offered by NGRE and Jython.
In particular the possibility of associating metadata to items within rules seems to me very powerful: it would allow to considerably simplify the items definition file. Moreover I am willing to improve my Python knowledge using Jython. On the other hand, I’ve read that Jython implements Python at version 2.7, while the mainstream Python is now at version 3 and version 2.7 has been declared obsolete. According to this post It seems that there are no near-term plans for upgrading Jython to version 3.
Finally, I noticed that NGRE is somewhat agnostic with respect to the language: apparently it can work with Javascript and Groovy as well.

So the final naive question is: is Jython here to stay, so that it is worth investing in learning it (even though I will have to live with the difference between the 2.7 and 3 versions of the python language), or will it be superseded by something else?

If this has already been discussed elsewhere please let me know where, as I did not find it.
Thank you for your attention,
Lionelllo

Python3 will eventually be available for use in scripted automation, and possibly in a couple forms. Whichever form is used, there will be very limited, if any, migration needed for scripts and modules written for Jython 2.7, so there should be no concern of obsolescence. Jython development is active and there is a possibility that some form of Jython3 could be available before OH 3.0 is released, but I think that would be unlikely if we are targeting an end of year release. Graal-python is also an option, but it looks to be not quite fully baked.

Before Sebastian pops up :slight_smile:, you could use Python3 with the third-party rule engine HABApp, but it is far from scripted automation and is limited to the functionality available in the REST API.

If you search the forum for Jython3, you’ll find some discussions. Here is one…

Hopefully soon, the maintainers will decide what I need to do to get the Jython and helper library add-ons merged. Until then, you can use this…

Once the Jython add-ons have been merged, I will submit add-ons for Nashorn, Kotlin, Groovy, and jRuby.

4 Likes

Thank 5iver you for your informative answer.
Meanwhile I’ve seen that Rlkoshak is updating its Design Patterns with Jython, and he also documented his path in migration. As I’m not in a hurry, I’ll gradually start from small rules and practice with the use of functions and metadata.

4 Likes