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.serial.internal.util;
15 import java.util.Arrays;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.io.transport.serial.SerialPort;
21 * Enum to convert config stopBits value to serial port value
23 * @author Mike Major - Initial contribution
26 public enum StopBits {
27 STOPBITS_1("1", SerialPort.STOPBITS_1),
28 STOPBITS_1_5("1.5", SerialPort.STOPBITS_1_5),
29 STOPBITS_2("2", SerialPort.STOPBITS_2);
31 final String configValue;
32 final int serialPortValue;
34 private StopBits(final String configValue, final int serialPortValue) {
35 this.configValue = configValue;
36 this.serialPortValue = serialPortValue;
40 * Return the serial port value
42 * @return the serial port value
44 public int getSerialPortValue() {
45 return serialPortValue;
49 * Return the enum value from the config value
51 * @param configValue the config value
52 * @return the enum value
54 public static StopBits fromConfig(final String configValue) {
55 return Arrays.asList(values()).stream().filter(p -> p.configValue.equals(configValue)).findFirst()