Skip to content
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

event data payload differs from UI to file-bases rules #111

Closed
florian-h05 opened this issue Apr 24, 2022 · 6 comments
Closed

event data payload differs from UI to file-bases rules #111

florian-h05 opened this issue Apr 24, 2022 · 6 comments
Labels
wontfix This will not be worked on

Comments

@florian-h05
Copy link
Contributor

As already noticed in some PRs (#106, #110), the event object differs from UI-based to file-based rules.

In file-based rules the event data is "formatted" by getTriggeredData(input).

A solution to unify the event object of both would be to simply expose the above mentioned function and to advise the user to add the following on top of his UI rules:

if (typeof event !== 'undefined') event = require('openhab').rules.getTriggeredData(new Map().set('event', event));

Is there any way to put automatically add content to UI scripts?

WDYT @digitaldan @jpg0 ?

@jpg0
Copy link
Collaborator

jpg0 commented Apr 24, 2022

Whilst that would technically work in this case, my fear is that due to there being different implementations triggering the rules, this is only a hack rather than a proper solution. It won't fix all differences (e.g. can you use const in UI rules yet?), and may also break if the current wrapping code changes.

As for whether it's possible to inject this transparently, sure, it's possible.

@florian-h05
Copy link
Contributor Author

my fear is that due to there being different implementations triggering the rules, this is only a hack rather than a proper solution.

So you would not advise to inject or add that to the top of MainUI scripts?

By the way, I found one more difference between UI and file based: UI based scripts do not reload on changes in node_modules.
You have to disable/enable them to reload dependencies.

@ssalonen
Copy link
Contributor

e.g. can you use const in UI rules yet?

yeah to my knowledge const rules are not supported since context is 'reused'. That particular limitation can be hacked around by wrapping with IIFE, (function () { .. })() to my knowledge. However, that might suffer from this context differences ? (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this)

@jpg0
Copy link
Collaborator

jpg0 commented Apr 28, 2022

So you would not advise to inject or add that to the top of MainUI scripts?

Probably not, no. The real* problem here is that the script execution environment differs (e.g. the const problem, dependency reloading, etc), and this is the thing that needs fixing. Injecting scripts in one environment doesn't really fix the underlying problem; it may bring some things a little closer, but also makes the whole system even more complex.

*The real problem may actually be the semantic meaning of file-based and UI-based scripts differ. File-based scripts are run at startup and reload time (only) and register things that they want, like rules and triggers, somewhat like a system-based plugin may do. UI-based scripts are executed based on a specific action that occurs in OH, but their execution is typically ephemeral and stateless. I'm not sure that we've spent the time thinking about how these two things interact and complement each other - we are kind-of squinting and saying that File and UI doesn't matter and they are the same thing, but they're probably not.

@ssalonen
Copy link
Contributor

Does the workaround in the first post work for thing status update triggers?

@florian-h05 florian-h05 added wontfix This will not be worked on and removed enhancement New feature or request labels Jun 14, 2022
@florian-h05
Copy link
Contributor Author

Closing as we won‘t fix this here as this is related to openHAB Core.

@florian-h05 florian-h05 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants