Closed Boldfor closed 3 weeks ago
/cc @stefan-hoehn
Before we go on, can you make sure you are using a typed variable like described here: https://www.openhab.org/docs/configuration/blockly/#using-variables
@stefan-hoehn, I just re-created the variable as a typed variable with the type "Thing name":
The error is the same:
2024-07-15 20:41:13.033 [ERROR] [script.javascript.thing_status_check] - Failed to execute script: TypeError: things.getThing is not a function
at <js>.:program(<eval>:8)
at org.graalvm.polyglot.Context.eval(Context.java:399)
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458)
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:426)
at java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:262)
... 75 more
2024-07-15 20:41:13.033 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'thing_status_check' failed: org.graalvm.polyglot.PolyglotException: TypeError: things.getThing is not a function
What's odd: When I check the generated code, I cannot see the type the variable was defined as (not sure if this should look differently):
var things;
console.warn('Regeln zum Checken der Thing-Status wird ausgeführt.');
var things_list = things.getThings();
for (var things_index in things_list) {
things = things_list[things_index];
if (things.getThing(things).status != 'ONLINE' && things.getThing(things).status != 'INITIALIZING') {
console.info(things.getThing(things).statusInfo);
console.info(things.getThing(things).status);
console.info(things.getThing(things).status);
}
}
This works fine:
Your code breaks on the "get thing status" block. This block DOES NOT take a thing object! It is meant to be used with a thing-block. A thing block, though, similar to an item block, does hold the id which is uid of thing. See the two blocks at. the beginning of the above sample. So, if you really wanted to use it (though there is no good reason because get-status-of-thing does the same but with a thing object, you have to supply the uid of the thing to that block.
@stefan-hoehn , thanks a lot for the explanation.
So should I close this issue? Or is this one of the cases where restrictions can be applied in blockly, so that the user can't even put blocks together that won't work?
You actually have a point here. I made that block smarter now:
See the related fix for that.
You actually have a point here. I made that block smarter now:
Nice. After almost three years of OH I could (indirectly via you) also make a contribution to the actual code. 😃
The problem
In blockly, when using the new loop function for things, the block "get of " or "get of <variable name"" works as intended. The block "get thing status however throws an error. Also discussed here: https://github.com/openhab/openhab-webui/pull/2562#issuecomment-2223821057
Expected behavior
The way I understood the "get things status" block, if used in a loop, it should produce the same result than the "get of <variable name"-block.
Steps to reproduce
On OH 4.2, execute the following rule:
Your environment
Browser console
Browser network traffic
Additional information