From 4ea61d38dd27428040788a7047c8610b4ea86679 Mon Sep 17 00:00:00 2001 From: Holger Hees Date: Sat, 10 May 2025 19:25:01 +0200 Subject: [PATCH] [pythonscripting] Fix python timedelta to java duration mapping (#18671) * fix python timedelta to java duration mapping * fix duration accuracy --- 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 6d48a556c16..41d9fa92a8a 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 3cceeb2eac8..d53c7ccda11 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(Math.round(v.invokeMember("total_seconds").asDouble() * 1000000000)), HostAccess.TargetMappingPrecedence.LOW) // Translate python item to org.openhab.core.items.Item