-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Docs: document UI rules event and @runtime #110
Conversation
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.
Overall looks really well, just a few spelling and formatting points.
Yes, it is also available in file-based scripts/rules. |
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👍
Thank you @ssalonen.
We need @digitaldan or @jpg0 for merging. |
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.
Thanks! Looks good, i had only one suggestion
@digitaldan |
Yeah, i have been thinking this was happening already, but forgot repos defaults to not squashing, i just changed the settings so now squashing always happens, thanks for noticing ! |
I took the liberty of moving init/deinit hook sections: 9f03898 |
@ssalonen this looks great, thanks! I like the advanced scripting section, i can see additional parts being added to that over time. |
Can you fix the conflicts that have popped up due to other PR merges? |
Signed-off-by: Sami Salonen <ssalonen@gmail.com>
Signed-off-by: Sami Salonen <ssalonen@gmail.com>
Signed-off-by: Sami Salonen <ssalonen@gmail.com>
Signed-off-by: Sami Salonen <ssalonen@gmail.com>
Signed-off-by: Sami Salonen <ssalonen@gmail.com>
Signed-off-by: Sami Salonen <ssalonen@gmail.com>
Signed-off-by: Sami Salonen <ssalonen@gmail.com>
Signed-off-by: Sami Salonen <ssalonen@gmail.com> Co-Authored-By: Dan Cunningham <dan@digitaldan.com> Co-authored-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Sami Salonen <ssalonen@gmail.com>
Also: - title capitalization now reflecting code Signed-off-by: Sami Salonen <ssalonen@gmail.com>
Emulating merge error with openhab#99 Signed-off-by: Sami Salonen <ssalonen@gmail.com>
Emulating merge error with openhab#99 Signed-off-by: Sami Salonen <ssalonen@gmail.com> Signed-off-by: Sami Salonen <ssalonen@gmail.com>
@digitaldan should be now OK. PR #99 caused a lot of issue for rebase, it seemed to break havoc to many parts of the doc... Best to verify diff of this PR to ensure it is OK |
I didn't see an answer to this. You can |
It was confirmed that it is also in file-based rules.
Personally I do not agree with this (to my mind) simplified statement. Without However, you are correct that some of the functionality makes sense only for migration purposes. In fact, I have written guidance as follows:
Anecdotally, you can still do plenty without |
Of course the use of @runtime can cause conflicts, but it is listed under advanced scripting and there is a note that the usage of openhab-js instead is recommended.
That would be one-thing that we should improve in openhab-js. |
To be clear, whilst we should prefer using openhab-js objects rather than importing @runtime, it should not cause any conflicts. No JS Dev who knows what they are doing will copy all the imports to the global namespace, this is just asking for trouble and no-one does it. They would import it to a const or let, named something like |
No, you don't need the entirety of @runtime to work with QuantityTypes. And I've already opened an issue and started experimenting with ways to manage QuantityTypes in the library where possible (see #102) . Lack of operator overloading will make it challenging though. But ideally I'd like users to be able to compare and do math with numbers and QuantityTypes interchangeably without having to worry about units unless they want to. Anyway, you have two choices. Option one is to throw out the units:
You can event force it to °F if you need to.
No imports are required at all with this approach but, of course, it works best when you are working with constants and such. If you are working with to QuantityTypes it's probably best not to throw out the units. It also requires you to know ahead of time that the Item is a Number:X. But yes, you'd have to either
Importing just QuantityType from @runtime would look something like the following I think.
I've no problem with documenting So I agree it's an advanced topic and not something most users should be using as a kind of default import. |
A rule of thumb as to when |
Wouldn't you want to use |
Sorry, yes, you're right. I forgot that I added this to the JS layer. I guess the only remaining reason is for anything which the devs have (a) added to |
(@rkoshak )
Personally, (and this is just me personally!), I prefer to have the framework protect against incompatible units and such. Also, the As you said
Don't get me wrong, I am all for 'native' js adaptation of core java types, and have those documented from a common place. I can imagine the current setup is jarring for new users as you need to lookup and combine documentation from many places. This would be ideal, user would live in pure javascript world and would have no need to understand java and how the GraalVM adapts Java types into js. |
With the introduction of Nashorn as a separate add-on (see https://community.openhab.org/t/jsscripting-nashorn/134770) I don't think there really is a need for such migration any more. To move to JS Scripting with openhab-js will require a significant rewrite of the rules, a rewrite that needs to not include Even so, it's not really migration as much as it is backward compatibility. By including
Agreed, that's why I opened #102.
I think we all agree that is the goal for openhab-js. But
This is a decision I've struggled with. Early on a decision was made to just make everything a String. It makes a lot of sense most of the time but breaks down when you have QuantityTypes, as you point out. You can get at the raw Java State Object from Item using You can maybe get at the raw Item's state from the Event Object using And of course, in the UI we get that raw Java |
Open questions
@runtime
available in file based rules? If not, it should be mentioned in docsNot documented