2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.ihc.internal.converters;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.openhab.binding.ihc.internal.ws.exeptions.ConversionException;
17 import org.openhab.binding.ihc.internal.ws.projectfile.IhcEnumValue;
18 import org.openhab.binding.ihc.internal.ws.resourcevalues.WSEnumValue;
19 import org.openhab.core.library.types.StringType;
22 * StringType {@literal <->} WSEnumValue converter.
24 * @author Pauli Anttila - Initial contribution
26 public class StringTypeWSEnumValueConverter implements Converter<WSEnumValue, StringType> {
29 public StringType convertFromResourceValue(@NonNull WSEnumValue from, @NonNull ConverterAdditionalInfo convertData)
30 throws ConversionException {
31 return new StringType(from.enumName);
35 public WSEnumValue convertFromOHType(@NonNull StringType from, @NonNull WSEnumValue value,
36 @NonNull ConverterAdditionalInfo convertData) throws ConversionException {
37 if (convertData.getEnumValues() != null) {
38 for (IhcEnumValue item : convertData.getEnumValues()) {
39 if (item.getName().equals(from.toString())) {
40 return new WSEnumValue(value.resourceID, value.definitionTypeID, item.getId(), item.getName());
43 throw new ConversionException("Can't find enum value for string " + value.toString());
45 throw new ConversionException("Enum list is null");