diff --git a/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleEventHandler.java b/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleEventHandler.java index 6e361e81..4ff150d9 100644 --- a/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleEventHandler.java +++ b/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleEventHandler.java @@ -47,6 +47,7 @@ import org.openhab.core.library.types.OpenClosedType; import org.openhab.core.library.types.PercentType; import org.openhab.core.library.types.PlayPauseType; +import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.types.StopMoveType; import org.openhab.core.library.types.StringType; import org.openhab.core.library.types.UpDownType; @@ -397,6 +398,8 @@ public Double getStateFromItemAsDouble(String name) { } if (state instanceof PercentType) { return ((PercentType) state).doubleValue(); + } else if (state instanceof QuantityType) { + return ((QuantityType) state).doubleValue(); } else { DecimalType decimalType = state.as(DecimalType.class); return decimalType != null ? decimalType.doubleValue() : null; diff --git a/src/main/java/org/openhab/automation/jrule/rules/JRuleEvent.java b/src/main/java/org/openhab/automation/jrule/rules/JRuleEvent.java index 91ad6229..fe693695 100644 --- a/src/main/java/org/openhab/automation/jrule/rules/JRuleEvent.java +++ b/src/main/java/org/openhab/automation/jrule/rules/JRuleEvent.java @@ -15,6 +15,9 @@ import org.openhab.automation.jrule.rules.value.JRuleOnOffValue; import org.openhab.automation.jrule.rules.value.JRuleOpenClosedValue; import org.openhab.automation.jrule.rules.value.JRuleUpDownValue; +import org.openhab.core.library.types.QuantityType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The {@link JRuleEvent} @@ -23,6 +26,8 @@ */ public class JRuleEvent { + private static final Logger logger = LoggerFactory.getLogger(JRuleEvent.class); + private final String value; private String memberName; @@ -53,23 +58,21 @@ public JRuleUpDownValue getValueAsUpDownValue() { } public Double getValueAsDouble() { - Double d = null; try { - d = Double.parseDouble(value); - } catch (NumberFormatException x) { - // ignore + return QuantityType.valueOf(value).doubleValue(); + } catch (Exception e) { + logger.warn("Error converting {} to double: {}", value, e.getMessage()); + return null; } - return d; } public Integer getValueAsInteger() { - Integer i = null; try { - i = Integer.parseInt(value); - } catch (NumberFormatException x) { - // ignore + return QuantityType.valueOf(value).intValue(); + } catch (Exception e) { + logger.warn("Error converting {} to int: {}", value, e.getMessage()); + return null; } - return i; } public String getMemberName() {