Skip to content

Commit

Permalink
Supports translating openhab-js Item to OH native Item
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
  • Loading branch information
digitaldan committed Feb 19, 2022
1 parent f29034f commit 65f3408
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.openhab.automation.jsscripting.internal.fs.watch.JSDependencyTracker;
import org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable;
import org.openhab.core.automation.module.script.ScriptExtensionAccessor;
import org.openhab.core.items.Item;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -97,7 +98,10 @@ public OpenhabGraalJSScriptEngine(@Nullable String injectionCode) {
(v) -> v.hasMember("minusDuration") && v.hasMember("toNanos"), v -> {
return Duration.ofNanos(v.invokeMember("toNanos").asLong());
}, HostAccess.TargetMappingPrecedence.LOW)
.build();
// Translate openhab-js Item to org.openhab.core.items.Item
.targetTypeMapping(Value.class, Item.class, (v) -> v.hasMember("rawItem"), v -> {
return v.getMember("rawItem").as(Item.class);
}, HostAccess.TargetMappingPrecedence.LOW).build();

delegate = GraalJSScriptEngine.create(
Engine.newBuilder().allowExperimentalOptions(true).option("engine.WarnInterpreterOnly", "false")
Expand Down

0 comments on commit 65f3408

Please sign in to comment.