Issue with contextual info block after upgrading to 4.2

Hi there,

after upgrading my openHAB instance to 4.2 i encountered an issue with at least one of my rules not running correctly anymore.

From my point of view this is an issue with insufficient use of grouping in if statements appearing due to recent blockly changes.

Snippet:
Bildschirmfoto 2024-07-21 um 12.39.50

This results in the following code:

var priceValue;

priceValue = event.itemState !== undefined ? parseFloat(event.itemState.toString()) : undefined;
console.info((priceValue > 2));
console.info((event.itemState !== undefined ? parseFloat(event.itemState.toString()) : undefined > 2));

The first log outputs to ‘true’ or ‘false’ as intended, while the second outputs the item value.

If memory serves me right in previously releases the ‘contextual info as number’ block would just translate to ‘parseFloat(…)’ but with the introduction of the undefined check this messes up surrounding if statements.

Anybody else seeing this?

I actually like the ‘undefined check change’ since it helped me clean up some other rules, but maybe the if statement, by default, should put the two operands into brackets to avoid running into this issue.

Can you double check if that code would be okay?

console.info((((event.itemState !== undefined) ? parseFloat(event.itemState.toString()) : undefined) > 2));

(and yes, I could probably omit the brackets around the condition itself.)

cc @florian-h05
cc @Larsen is this the same like yours : https://community.openhab.org/t/bug-in-blocky-contextual-info/157294

1 Like

Did a quick test and it seems to work OK.

1 Like

@stefan.hoehn : Yes, that’s the same. And with the additional brackets it works fine.

1 Like