-
-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor ScriptExecution to plain Java ScriptExtension #3155
Conversation
Signed-off-by: Jan N. Klug <github@klug.nrw>
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/js-scripting-why-are-we-deprecated-createtimer/140748/15 |
@florian-h05 Is that what you would expect? |
Wow, that was fast Jan 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much nicer. I was just working with createTimer from the jrubyscripting library yesterday, and was wondering why it wasn't just using a Runnable.
...e.script/src/main/java/org/openhab/core/automation/module/script/action/ScriptExecution.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Jan N. Klug <github@klug.nrw>
* @param closure the code block to execute | ||
* @return a handle to the created timer, so that it can be canceled or rescheduled | ||
*/ | ||
Timer createTimer(ZonedDateTime instant, Runnable closure); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming of the ZonedDateTime
as instant triggers me to ask the question: Would an Instant
be sufficient here, since the the point in time doesn't care about time-zone? If ZonedDateTime
is more convenient, consider if parameter should be renamed for clarity, and/or if a variant taking Instant
would be relevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs actually say it should be an AbstractInstant
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AbstractInstant
is surely wrong because that's a class from joda-time which we don't use anymore. So the docs need to be updated.
IMO an Instant
would also be fine (also see my comment on #2898) but I re-implemented what we have in DSL and that is a ZonedDateTime
. If we try to solve that now, we won't get a solution before next release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of interest: Why can't we get a solution if we try that before next release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always felt that the docs references to abstract classes like this was confusing to new users anyway. I'm not sure Instant
is any better but it's at least consistent. When/if this ever changes here to Instant
, we should also change the persistence actions which are documented as using ZonedDateTime
to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be my proposal. IMO user-facing ZDT and Instant don‘t make much difference, so using Instant internally in DateTimeType and ZDT in rules is fine. Does it make a difference in JS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make a difference in JS?
Regarding the compatibility, no.
We are using JS-Joda as date and time library, which provides the same functionality that the Joda time library had (ZonedDateTime, Instant and so on).
When core moves from ZonedDateTime to Instant, we only need to use Instant from JS-Joda instead of ZonedDateTime from JS-Joda.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no real benefit (I don't see one for DSL or JavaRule), we should probably stay where we are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only difference I can see is, which argument and which string the parse
function takes and that instance has function like ofEpochMillis
. But we have a nice utility function that parses many different date and/or time representations to a ZonedDateTime, so I can’t see any benefit in using an Instant.
Given the large number of scripts that have to be updated when that’s changed to an Instant, I agree that we should probably stay on ZonedDateTime.
The question for now is: should we rename the parameter from instant to zdt or zonedDateTime or something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I‘ll update that.
closure.apply(); | ||
}, identifier); | ||
@ActionDoc(text = "create an identifiable timer ") | ||
public static Timer createTimer(@Nullable String identifier, ZonedDateTime zonedDateTime, Procedures.Procedure0 closure) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static Timer createTimer(@Nullable String identifier, ZonedDateTime zonedDateTime, Procedures.Procedure0 closure) { | |
public static Timer createTimer(@Nullable String identifier, ZonedDateTime zonedDateTime, Procedures.Procedure0 closure) { |
closure.apply(arg1); | ||
}, identifier); | ||
@ActionDoc(text = "create an identifiable timer with argument") | ||
public static Timer createTimerWithArgument(@Nullable String identifier, ZonedDateTime zonedDateTime, Object arg1, Procedures.Procedure1 closure) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static Timer createTimerWithArgument(@Nullable String identifier, ZonedDateTime zonedDateTime, Object arg1, Procedures.Procedure1 closure) { | |
public static Timer createTimerWithArgument(@Nullable String identifier, ZonedDateTime zonedDateTime, Object arg1, Procedures.Procedure1 closure) { |
@J-N-K Just one thing I am wondering: I've seen that you implemented a |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/js-scripting-why-are-we-deprecated-createtimer/140748/17 |
@J-N-K What do you think, when does this PR get merged? |
I'm probably the last person with an answer to this: I can't review and merge my own PR. |
@kaikreuzer @cweitkamp @wborn Just asking, WDYT when can you review and merge this PR? openhab/openhab-addons#13695 depends on this. |
Signed-off-by: Jan N. Klug <github@klug.nrw>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks!
* Refactor ScriptExecution to plain Java ScriptExtension * keep callScript backward compatible Signed-off-by: Jan N. Klug <github@klug.nrw> GitOrigin-RevId: c340e8d
JSR-223 automation add-ons often use the script actions from the
org.openhab.core.model.script
bundle. The downside is that the actions are tied to XText, making it impossible for the automation add-ons to modify/wrap these actions without explicit dependency on XText (see #3128).This is the first step to refactor these actions to plain Java, making them available as
ScriptExtension
via an import-presetScriptAction
which is not imported by default to prevent unwanted shadowing of other components. They are wrapped for DSL rules, to stay backward compatible.Signed-off-by: Jan N. Klug github@klug.nrw