From edfd6f72eb468ecc5b2d80e8298aa9f0c7ca673f Mon Sep 17 00:00:00 2001 From: Arne Seime Date: Mon, 19 Sep 2022 18:02:33 +0200 Subject: [PATCH] Another fix for handling double values in rule conditions. Values may be UNDEF or NULL --- .../jrule/internal/engine/JRuleEngine.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/openhab/automation/jrule/internal/engine/JRuleEngine.java b/src/main/java/org/openhab/automation/jrule/internal/engine/JRuleEngine.java index 9accd3f5..1443762f 100644 --- a/src/main/java/org/openhab/automation/jrule/internal/engine/JRuleEngine.java +++ b/src/main/java/org/openhab/automation/jrule/internal/engine/JRuleEngine.java @@ -443,14 +443,20 @@ private Boolean evaluateComparatorParameters(Double gt, Double gte, Double lt, D return stateValue.equals(eq); } else if (neq != null) { return !stateValue.equals(neq); - } else if (gt != null) { - return getValueAsDouble(stateValue) > gt; - } else if (gte != null) { - return getValueAsDouble(stateValue) >= gte; - } else if (lt != null) { - return getValueAsDouble(stateValue) < lt; - } else if (lte != null) { - return getValueAsDouble(stateValue) <= lte; + } else { + // valueAsDouble may be null if unparseable ("NULL" or "UNDEF") + Double valueAsDouble = getValueAsDouble(stateValue); + if (valueAsDouble == null) { + return null; + } else if (gt != null) { + return valueAsDouble > gt; + } else if (gte != null) { + return valueAsDouble >= gte; + } else if (lt != null) { + return valueAsDouble < lt; + } else if (lte != null) { + return valueAsDouble <= lte; + } } return null; }