-
Notifications
You must be signed in to change notification settings - Fork 2
Update README.md to highlight OH 2.5 requirement #2
Comments
So the version dependency exists as I built against 2.5.x, because that was what I pulled from github :) It may well be the case that it will run on 2.4.x if it's told to try. I'm happy to rebuild and widen the accepted dependency versions if you want to give it go on 2.4 before the break? You're also welcome to tweak it directly in the bundle jar too if you like - the versions that it wants are in META-INF/MANIFEST.MF, you'd just need to find all the occurrences of |
So I've got a little further today ... but not quite there :( The npm package seemed out of date, so I cloned straight from here instead. ... running on OH 2.5 now :) problem when running scripts now - ... seems to be related to osgi.js ... ... possibly related to openhab/openhab-core#1214 Unfortunately, I don't really know where to start digging in OH core to figure out how to change things :( |
Ah, that's because you have the latest JS, but I don't think the latest bundle jar. I've attached a zip of the jar (GH allows zips but not jars), so if you unzip it and give it a go it should work. The actual issue is that I added a 'services' script extension to give scripts an API to lookup/register/unregister their own osgi services. Anywhere you see an import of a module org.openhab.automation.module.script.graaljs-2.5.0-SNAPSHOT.jar.zip |
Thanks for this - between OH2.5 & this, xmas has definitely come early! :) I've spent a large chunk of this evening rewriting my old js rules. Here is one of the latest - I'd really appreciate your comments, as I'm sure there will be simpler / cleaner ways of doing things:
... also, is there any object context that can be passed into the then - e.g. Many thanks for all your work - I'll spend a while familiarizing myself with things some more - I'd be happy to lend a hand going forward - Jamie. |
Awesome! Great to see that you've got it working! Hopefully those rules are a lot more concise than they were in the old rules engine! As for improving further, things I'd suggest:
|
... that's very generous of you, describing it as the "old rules engine" ... not what I'd call it ;)
Yes - a good idea - I've been trying to get my old rules to run first - optimising comes next, once I know what I'm doing :)
Here is another of my rules - which is now even simpler with the use of the receivedCommand:
... I might be being greedy right now, but I'd rather write that like this:
... thanks again - Jamie. |
Hmm, that exact syntax wouldn't be simple to support, because One option would instead to be to support templating, such that you could: I think that would support that direct case, but do you have others that need a similar context being passed? |
So I'm making good progress, but... I can't seem to get a java.util.Timer to work:
Throws:
Any ideas? |
I haven't used Timers, but you're seeing a GraalJS error which is saying that it cannot invoke the 'schedule' method on the Timer class because it cannot provide it with the correct argument types. Looking at the method signature, it accepts a 'TimerTask'. I see that you've provided a function - this is something that GraalJS can convert to the correct type of interface for java, but only if it's an interface with a single method and is marked as a @FunctionalInterface. TimerTask is an abstract class with a few methods, so it needs explicit extension. I just tried out the following code which worked for me (note the explicit creation of a TimerTask, and the syntax to implement the 'run' method):
It's a bit cumbersome, but if you're doing it a lot it would be pretty simple to create a single JS function with callback (just like setTimeout) in a module. |
Absolute hero - works here too - thanks! I didn't try that myself, as looking at the "old rule engine", it didn't seem necessary ... I has a feeling it might be a difference with the GraaalJS implementation - a useful lesson :) |
When you say 'old rules engine', do you mean the Xtend-based one, or the ES5/Nashorn one? |
Oh, and BTW, I'm thinking that if there are other things that come up, it may be better posting on the OH community pages so that others can more easily find them. If you want to tag me on the post @jpg0 so that I get notified that's fine. |
Not sure - I didn't know there was more than one. utils.js contains:
|
No problem - somwehere like: https://community.openhab.org/c/setup-configuration-and-use/scripts-rules ??? |
That JS code you posted is from the ES5 script engine, which I agree is not 'old'! I was referring to the previous engine, which was based on the Xtend language, not JS at all. Interesting that that util.js code allows passing a function directly though; the is running on the Nashorn JS engine (which is now deprecated) - it does have some differences with the current Graal engine, mainly around interop with Java. And yes that topic on community is fine! |
Hello,
So this looks like a huge improvement on the current JS library, so I thought I'd have a go this evening ... unfortunately, it looks like I can't just drop the GraalJS bundle into my addons folder - as it complains:
... I'm guessing that I can't play with things until I update to 2.5 (a job I'm saving for the xmas break :)
Jamie.
The text was updated successfully, but these errors were encountered: