Skip to content

Conversation

stefan-hoehn
Copy link
Contributor

Depends on: openhab/openhab-addons#19443

Lately there was a change on the attributes of the event object. This PR adapts the event block to this new naming and prevents warning messages in the logs.

Additionally a new return block was added to the "Run & Process" category with return parameter.

image image
  1. The block without a return parameter is a nice improvement to easily leave a script without using non-elegant if/else statements. Bei adding the return statement the script is immediately ended. In this case the return parameter is not important.
  2. By adding a return parameter (in particular true or false) this can be used for condition, e.g. by using this condition:
image

which can implemented by using an inline blockly script that evaluates to true or false.

Signed-off-by: Stefan Höhn <mail@stefanhoehn.com>
@relativeci
Copy link

relativeci bot commented Oct 8, 2025

#3444 Bundle Size — 11.38MiB (~+0.01%).

4724d7c(current) vs f3c50b4 main#3443(baseline)

Warning

Bundle contains 2 duplicate packages – View duplicate packages

Bundle metrics  no changes
                 Current
#3444
     Baseline
#3443
No change  Initial JS 2.01MiB 2.01MiB
No change  Initial CSS 577.53KiB 577.53KiB
No change  Cache Invalidation 18.49% 18.49%
No change  Chunks 254 254
No change  Assets 277 277
No change  Modules 3035 3035
No change  Duplicate Modules 163 163
No change  Duplicate Code 1.85% 1.85%
No change  Packages 99 99
No change  Duplicate Packages 2 2
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#3444
     Baseline
#3443
Regression  JS 9.58MiB (+0.01%) 9.58MiB
No change  CSS 875.3KiB 875.3KiB
No change  Fonts 526.1KiB 526.1KiB
No change  Media 295.6KiB 295.6KiB
No change  IMG 140.74KiB 140.74KiB
No change  HTML 1.39KiB 1.39KiB
No change  Other 871B 871B

Bundle analysis reportBranch stefan-hoehn:blockly_migrate_eve...Project dashboard


Generated by RelativeCIDocumentationReport issue

@rkoshak
Copy link

rkoshak commented Oct 8, 2025

When you add the docs, make sure to make it clear that return can only be used when the wrapper is enabled in the JS Scripting configs (MainUI -> Settings -> JS Scripting.

@florian-h05
Copy link
Contributor

Our idea was to make blockly automatically set the directive to enable the wrapper when return is used.

@stefan-hoehn
Copy link
Contributor Author

you can actually see this in line 397 that creates "use wrapper" in the code.

@rkoshak
Copy link

rkoshak commented Oct 13, 2025

Is that something that can be done from a JS script? For example a rule template?

I think I've found ways for my templates to work around that but knowing it's possible might prove helpful in the future.

@florian-h05
Copy link
Contributor

Is that something that can be done from a JS script? For example a rule template?

I haven't written docs for that yet, but the 'use wrapper' directive can be used in any JavaScript condition in the UI.
It just has to be first or second line, i.e. top of the script.
For actions, you don't need it, there the wrapper is always on (unless you explictly disable it, but that's mainly implemented for the case there is any unexpected issue).

@rkoshak
Copy link

rkoshak commented Oct 14, 2025

So I can enable the wrapper but not disable the wrapper? I'm not trying to argue about anything, just understand in case it's helpful to me in the rule templates and so I understand how it works in Blockly so I can help on the forum better.

And don't you have actions and conditions backwards in your description. I thought the decision was to always enable it for Conditions and optionally enable it for Actions based on the add-on property. I could be remembering backwards, but that was what I thought. The reasoning was having the return statement in Conditions was worth keeping it always enabled, and doing so had minimal impact.

@stefan-hoehn
Copy link
Contributor Author

Not sure if it helps. As soon as Blockly adds one of these blocks, it adds "'use wrapper'" to the top of the script that it generates.

@florian-h05
Copy link
Contributor

florian-h05 commented Oct 22, 2025

You can also disable it, there are three ways of using the wrapper:

  • 'use wrapper'
  • 'use wrapper=true'
  • 'use wrapper=false'

The first two are equivalent.

And don't you have actions and conditions backwards in your description. I thought the decision was to always enable it for Conditions and optionally enable it for Actions based on the add-on property. I could be remembering backwards, but that was what I thought. The reasoning was having the return statement in Conditions was worth keeping it always enabled, and doing so had minimal impact.

I think you have to switch actions and conditions there. For actions, it is always enabled, since it has minimal to no impact, for conditions, there is the global add-on setting and the use wrapper directive to control the behaviour.

@rkoshak
Copy link

rkoshak commented Oct 22, 2025

You can also disable it, there are three ways of using the wrapper:

Excellent! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants