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.onewire.internal.device;
15 import static org.openhab.binding.onewire.internal.OwBindingConstants.BINDING_ID;
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.core.thing.type.ChannelTypeUID;
25 * The {@link OwChannelConfig} class defines a map entry
27 * @author Jan N. Klug - Initial contribution
30 public class OwChannelConfig {
31 private static final Pattern CONFIG_PATTERN = Pattern.compile("^(.+):(.+):(.*)$");
33 public String channelId;
34 public ChannelTypeUID channelTypeUID;
35 public @Nullable String label;
37 public OwChannelConfig(String channelId, ChannelTypeUID channelTypeUID, @Nullable String label) {
38 this.channelId = channelId;
39 this.channelTypeUID = channelTypeUID;
43 public OwChannelConfig(String channelId, ChannelTypeUID channelTypeUID) {
44 this(channelId, channelTypeUID, null);
47 public static OwChannelConfig fromString(String configString) {
48 Matcher matcher = CONFIG_PATTERN.matcher(configString);
49 if (matcher.matches()) {
50 if (matcher.group(3).trim().isEmpty()) {
51 return new OwChannelConfig(matcher.group(1).trim(),
52 new ChannelTypeUID(BINDING_ID, matcher.group(2).trim()));
54 return new OwChannelConfig(matcher.group(1).trim(),
55 new ChannelTypeUID(BINDING_ID, matcher.group(2).trim()), matcher.group(3).trim());
58 throw new IllegalArgumentException();
63 public String toString() {
64 return channelId + "/" + channelTypeUID.getAsString() + "/" + label;