diff --git a/bundles/org.openhab.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/StateDescriptionConverter.java b/bundles/org.openhab.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/StateDescriptionConverter.java index b1021d0b4..f174e3ad2 100644 --- a/bundles/org.openhab.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/StateDescriptionConverter.java +++ b/bundles/org.openhab.core.thing.xml/src/main/java/org/eclipse/smarthome/core/thing/xml/internal/StateDescriptionConverter.java @@ -16,6 +16,7 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import org.eclipse.smarthome.config.xml.util.ConverterAttributeMapValidator; import org.eclipse.smarthome.config.xml.util.GenericUnmarshaller; @@ -92,19 +93,10 @@ public class StateDescriptionConverter extends GenericUnmarshaller attributes = nodeValue.getAttributes(); - if ((attributes != null) && (attributes.containsKey("value"))) { - value = attributes.get("value"); - } else { - throw new ConversionException("The node 'option' requires the attribute 'value'!"); - } - - label = (String) nodeValue.getValue(); - - return new StateOption(value, label); + final Map attributes = nodeValue.getAttributes(); + final String value = Optional.ofNullable(attributes).map(entry -> entry.get("value")) + .orElseThrow(() -> new ConversionException("The node 'option' requires the attribute 'value'!")); + return new StateOption(value, nodeValue.getValue().toString()); } throw new ConversionException("Unknown type in the list of 'options'!");