I’m doing some Jython automations and I’m trying to do a conversion from ZonedDateTime to DateTime (Joda), but I get this error:
File "/opt/openhab2/conf/automation/lib/python/core/date.py", line 217, in to_joda_datetime
return DateTime(
IllegalArgumentException: java.lang.IllegalArgumentException: No instant converter found for type: java.time.Instant
It’s a little weird because of the conversion in the other way around works.
In summary
from core.date import toJodaDT
from org.joda.time import DateTime
from core.date import toJTime
toJTime(DateTime.now()) # Joda to Java works
toJodaDT(ZonedDateTime.now()) # Java to Joda doesn't work
@Bruce_Osborne He is looking after the Helper Libraries and most active on the forums, but I have been contributing to the project lately and wrote this particular module. Feel free to tag either of us for help with Jython rules, though Scott is far more knowledgeable.
I recommend bumping it up a few notches on your list! Python has a fairly shallow learning curve while still being a powerful language, and when comparing it to making rules in the DSL it might as well be another planet lol.
Well, busyness at work & home has restricted my hobby time.
I have also started helping clean up the zwave device database, in appreciation for all the hard work there.
Is there any real plans for a Python 3 variant? Python 2 is officially dead early next year.
We can’t move to Python 3 until we can move OH itself off of Java 8 and gain access to Graal VM (or the Jython folks decide to actually put in some effort to build and release a Python 3 variant, OH is wholly dependent on up stream libraries to provide support for stuff like this).
As far as Rules are concerned, the difference between Python 2.7 and 3 are almost non-existent. So waiting for Python 3 support isn’t really doing anything for you. The Rules will look the same either way.
Just because the Python folks will stop supporting 2.7 next year doesn’t mean that all of a sudden all Python 2 programs in the world will stop working. It just means there will be no more changes to the language, either to add new feature or to fix bugs.
Even if OH takes a long time to get support for Python 3 you are not running any major risks by adopting Jython’s 2.7 now.
You will have limited to no changes needed to your code to move to Python 3.
In the Rules development context, there is little or nothing that Python 3 offers that you will miss having to build your Rules.
Python 2.7 programs will continue to work for many years to come, they won’t automatically stop working when the foundation ends support.
Definitely make the move when you have the time but don’t let the fact that Jython only supports 2.7 keep you from making the move when you are ready.