From 836581ebc8dca7699605dccb9853a03c7bd6f4fa Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Sun, 28 Apr 2024 13:33:44 -0600 Subject: [PATCH] [mqtt] Treat incoming empty string as NULL for enum (#16641) Treat incoming empty string as NULL for enum (#16641) Signed-off-by: Cody Cutrer --- .../org/openhab/binding/mqtt/generic/values/TextValue.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 fb15998c41f2..c7a8462f0c44 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 State parseMessage(Command command) throws IllegalArgumentException { 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); }