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

[blockly] Adjust persistence blocks to breaking changes #2564

Merged
merged 4 commits into from
May 7, 2024

Conversation

florian-h05
Copy link
Contributor

@florian-h05 florian-h05 commented May 6, 2024

This adjusts the persistence blocks for the breaking changes of org.openhab.core.persistence.extensions.PersistenceExtensions.

For NashornJS, see openhab/openhab-core#3736 for the changes.
For GraalJS, see https://next.openhab.org/addons/automation/jsscripting/#itempersistence for the current API docs and openhab/openhab-js#331 for the changes.

In a follow-up PR, Blockly should be extended to make use of the new capabilities provided by the changed return type of variance, deviation, average, sum & delta.

@florian-h05 florian-h05 added enhancement New feature or request main ui Main UI labels May 6, 2024
@florian-h05 florian-h05 added this to the 4.2 milestone May 6, 2024
Copy link

relativeci bot commented May 6, 2024

#1952 Bundle Size — 10.6MiB (+0.03%).

98c07f9(current) vs 8779dcf main#1949(baseline)

Warning

Bundle contains 2 duplicate packages – View duplicate packages

Bundle metrics  Change 1 change
                 Current
#1952
     Baseline
#1949
No change  Initial JS 1.86MiB 1.86MiB
No change  Initial CSS 607.87KiB 607.87KiB
Change  Cache Invalidation 17.91% 0%
No change  Chunks 223 223
No change  Assets 246 246
No change  Modules 2876 2876
No change  Duplicate Modules 149 149
No change  Duplicate Code 1.86% 1.86%
No change  Packages 95 95
No change  Duplicate Packages 2 2
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#1952
     Baseline
#1949
Regression  JS 8.79MiB (+0.04%) 8.78MiB
No change  CSS 890.75KiB 890.75KiB
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.24KiB 1.24KiB
No change  Other 871B 871B

Bundle analysis reportBranch florian-h05:blockly-persistenceProject dashboard

Signed-off-by: Florian Hotze <[email protected]>
@florian-h05 florian-h05 marked this pull request as ready for review May 7, 2024 15:43
@florian-h05 florian-h05 requested a review from a team as a code owner May 7, 2024 15:43
@stefan-hoehn
Copy link
Contributor

Tested together in a session with @florian-h05 in an online session and looks good to us.
Can be merged.

This is a BREAKING change that requires all Blockly rules that use persistence blocks to be reopened and saved again.

@florian-h05 florian-h05 merged commit 8ed66cc into openhab:main May 7, 2024
6 checks passed
@florian-h05 florian-h05 deleted the blockly-persistence branch May 7, 2024 15:55
@mherwege
Copy link
Contributor

In a follow-up PR, Blockly should be extended to make use of the new capabilities provided by the changed return type of variance, deviation, average, sum & delta.

@stefan-hoehn Do you have plans to do this? This will be another breaking change and I think we should try to do it before the release to have all changes done in one go. I will have to adapt my blocky rules working with persistence and quantity-types myself, but it will make it a lot cleaner afterwards. Currently I convert to text and add the unit atthe end again before updating an item. I just want to work with the values with the unit. Typed variables will also help for this.

case 'varianceSince':
case 'varianceUntil':
dayInfo = javascriptGenerator.valueToCode(block, 'dayInfo', javascriptGenerator.ORDER_NONE)
code = (isGraalJs) ? `${itemCode}.persistence.${methodName}(${dayInfo}${persistenceExtension})?.numericState` : `parseFloat(${persistence}.${methodName}(${itemCode}, ${dayInfo}${persistenceExtension}).getState())`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefan-hoehn This is inconsistent. For GraalJS, you focus on keeping backward compatibility by returning numericState. For Nashorn, it returns the full state.
Moreover, by returning numericState in GraalJS, you basically strip the unit and make it impossible to do straight quantity calculations on the result. I understand this would be a breaking change to remove this, but I think we should do it now rather than wait until after 4.2.
As an alternative, one could create extra methods (something like deltaStateSince). That would allow to keep backward compatibility for GraalJS at the expense of having different and less intuitive names in Blockly vs pure JS. I would prefer the breaking change here.
@florian-h05 What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not inconsistent, for Nashorn there is also a numeric state returned (note the parseFloat around the state).

I have done this PR this way because after the breaking changes were done to code and the helper library, we needed to update Blockly quickly before the new milestone so it is not effectively „broken“.
Adjusting Blockly to allow use the new functionality was postponed to a later PR.

See #2595 (comment) for my implementation proposal.

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.

3 participants