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

Add context parameter to rule action #1582

Merged
merged 1 commit into from Dec 15, 2022
Merged

Conversation

ghys
Copy link
Member

@ghys ghys commented Dec 15, 2022

This adds the ability for "run rules" actions to pass a context to the rule.
See openhab/openhab-core#3160 & openhab/openhab-core#3160 (comment)

The context can be passed as a JSON string, or as a YAML structure (allowing to include expressions more easily), as illustrated below, the 2 versions are roughly equivalent except the second one includes an expression:

action: rule
actionRule: dump_context
actionRuleContext: '{ "param1": "value1", "param2": { "subkey1": "testing", "subkey2": 123 } }'


action: rule
actionRule: dump_context
actionRuleContext:
 param1: value1
 param2:
   subkey1: testing
   subkey2: 123
   computed: =2+3

The dump_context can be as simple as a JS (Nashorn or JS Scripting) script with the following code:

print(ctx);

which outputs:

{param1=value1, ruleUID=dump_context, param2={subkey1=testing, subkey2=123.0, computed=5.0}}

Signed-off-by: Yannick Schaus <github@schaus.net>
@ghys ghys requested a review from a team as a code owner December 15, 2022 13:59
@relativeci
Copy link

relativeci bot commented Dec 15, 2022

Job #652: Bundle Size — 15.96MiB (~+0.01%).

76dd7fc(current) vs 4fd6f8a main#651(baseline)

Metrics (2 changes)
                 Current
Job #652
     Baseline
Job #651
Initial JS 1.73MiB(+0.02%) 1.73MiB
Initial CSS 608.3KiB 608.3KiB
Cache Invalidation 90.48% 0.11%
Chunks 218 218
Assets 688 688
Modules 2007 2007
Duplicate Modules 108 108
Duplicate Code 1.8% 1.8%
Packages 133 133
Duplicate Packages 15 15
Total size by type (2 changes)
                 Current
Job #652
     Baseline
Job #651
CSS 856.34KiB 856.34KiB
Fonts 1.08MiB 1.08MiB
HTML 1.23KiB 1.23KiB
IMG 140.74KiB 140.74KiB
JS 9.03MiB (~+0.01%) 9.03MiB
Media 295.6KiB 295.6KiB
Other 4.59MiB (~-0.01%) 4.59MiB

View job #652 reportView main branch activity

@ghys ghys added enhancement New feature or request main ui Main UI labels Dec 15, 2022
@ghys ghys added this to the 3.4 milestone Dec 15, 2022
@ghys
Copy link
Member Author

ghys commented Dec 15, 2022

Willing to be personally liable for late merging this little feature, as it would be too bad not to leverage openhab/openhab-core#3160 :)
Have been tested with no regressions.

@ghys ghys merged commit e2f06a2 into openhab:main Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request main ui Main UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant