]> git.basschouten.com Git - openhab-addons.git/commitdiff
[mqtt] Treat incoming empty string as NULL for enum (#16641)
authorCody Cutrer <cody@cutrer.us>
Sun, 28 Apr 2024 19:33:44 +0000 (13:33 -0600)
committerGitHub <noreply@github.com>
Sun, 28 Apr 2024 19:33:44 +0000 (21:33 +0200)
Treat incoming empty string as NULL for enum (#16641)

Signed-off-by: Cody Cutrer <cody@cutrer.us>
bundles/org.openhab.binding.mqtt.generic/src/main/java/org/openhab/binding/mqtt/generic/values/TextValue.java

index fb15998c41f27f55d8e6be95c8703afb91f77a0b..c7a8462f0c441fad168d0cee5218dc9394269ff5 100644 (file)
@@ -106,7 +106,11 @@ public class TextValue extends Value {
         final Set<String> 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);
     }