From: Cody Cutrer Date: Sun, 28 Apr 2024 19:33:44 +0000 (-0600) Subject: [mqtt] Treat incoming empty string as NULL for enum (#16641) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=836581ebc8dca7699605dccb9853a03c7bd6f4fa;p=openhab-addons.git [mqtt] Treat incoming empty string as NULL for enum (#16641) Treat incoming empty string as NULL for enum (#16641) Signed-off-by: Cody Cutrer --- diff --git a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/TextValue.java b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/TextValue.java index fb15998c41..c7a8462f0c 100644 --- a/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/TextValue.java +++ b/bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/TextValue.java @@ -106,7 +106,11 @@ public class TextValue extends Value { final Set states = this.states; String valueStr = command.toString(); if (states != null && !states.contains(valueStr)) { - throw new IllegalArgumentException("Value " + valueStr + " not within range"); + if (valueStr.isEmpty()) { + return UnDefType.NULL; + } else { + throw new IllegalArgumentException("Value " + valueStr + " not within range"); + } } return new StringType(valueStr); }