From 3198a7a37c77cb5752fb1d578101b482a2f8fe2b Mon Sep 17 00:00:00 2001 From: Holger Hees Date: Sat, 10 May 2025 18:26:53 +0200 Subject: [PATCH 1/2] fix python timedelta to java duration mapping --- bundles/org.openhab.automation.pythonscripting/pom.xml | 2 +- .../automation/pythonscripting/internal/PythonScriptEngine.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.automation.pythonscripting/pom.xml b/bundles/org.openhab.automation.pythonscripting/pom.xml index 6d48a556c163c..41d9fa92a8a6d 100644 --- a/bundles/org.openhab.automation.pythonscripting/pom.xml +++ b/bundles/org.openhab.automation.pythonscripting/pom.xml @@ -80,7 +80,7 @@ scm:git:https://github.com/openhab/openhab-python ${project.build.directory}/python - v1.0.0-rc1 + v1.0.0-rc2 tag diff --git a/bundles/org.openhab.automation.pythonscripting/src/main/java/org/openhab/automation/pythonscripting/internal/PythonScriptEngine.java b/bundles/org.openhab.automation.pythonscripting/src/main/java/org/openhab/automation/pythonscripting/internal/PythonScriptEngine.java index 3cceeb2eac879..2052d85516b3e 100644 --- a/bundles/org.openhab.automation.pythonscripting/src/main/java/org/openhab/automation/pythonscripting/internal/PythonScriptEngine.java +++ b/bundles/org.openhab.automation.pythonscripting/src/main/java/org/openhab/automation/pythonscripting/internal/PythonScriptEngine.java @@ -121,7 +121,7 @@ public class PythonScriptEngine .targetTypeMapping(Value.class, Duration.class, // picking two members to check as Duration has many common function names v -> v.hasMember("total_seconds") && v.hasMember("total_seconds"), - v -> Duration.ofNanos(v.invokeMember("total_seconds").asLong() * 10000000), + v -> Duration.ofNanos(v.invokeMember("total_seconds").asLong() * 1000000000), HostAccess.TargetMappingPrecedence.LOW) // Translate python item to org.openhab.core.items.Item From 69ac69cd47ca6caa4b8b384d48b31e21de1108b4 Mon Sep 17 00:00:00 2001 From: Holger Hees Date: Sat, 10 May 2025 18:55:55 +0200 Subject: [PATCH 2/2] fix duration accuracy --- .../automation/pythonscripting/internal/PythonScriptEngine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.automation.pythonscripting/src/main/java/org/openhab/automation/pythonscripting/internal/PythonScriptEngine.java b/bundles/org.openhab.automation.pythonscripting/src/main/java/org/openhab/automation/pythonscripting/internal/PythonScriptEngine.java index 2052d85516b3e..d53c7ccda1134 100644 --- a/bundles/org.openhab.automation.pythonscripting/src/main/java/org/openhab/automation/pythonscripting/internal/PythonScriptEngine.java +++ b/bundles/org.openhab.automation.pythonscripting/src/main/java/org/openhab/automation/pythonscripting/internal/PythonScriptEngine.java @@ -121,7 +121,7 @@ public class PythonScriptEngine .targetTypeMapping(Value.class, Duration.class, // picking two members to check as Duration has many common function names v -> v.hasMember("total_seconds") && v.hasMember("total_seconds"), - v -> Duration.ofNanos(v.invokeMember("total_seconds").asLong() * 1000000000), + v -> Duration.ofNanos(Math.round(v.invokeMember("total_seconds").asDouble() * 1000000000)), HostAccess.TargetMappingPrecedence.LOW) // Translate python item to org.openhab.core.items.Item