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.intesis.internal.api;
15 import java.util.Arrays;
16 import java.util.List;
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;
24 * @author Cody Cutrer - Initial contribution
27 public class IntesisBoxMessage {
28 public static final String ID = "ID";
29 public static final String INFO = "INFO";
30 public static final String SET = "SET";
31 public static final String CHN = "CHN";
32 public static final String GET = "GET";
33 public static final String LOGIN = "LOGIN";
34 public static final String LOGOUT = "LOGOUT";
35 public static final String CFG = "CFG";
36 public static final String LIMITS = "LIMITS";
37 public static final String DISCOVER = "DISCOVER";
39 private static final Pattern REGEX = Pattern.compile("^([^,]+)(?:,(\\d+))?:([^,]+),([A-Z0-9.,\\[\\]]+)$");
41 @SuppressWarnings("unused")
42 private final String acNum;
43 private final String command;
44 private final String function;
45 private final String value;
47 private IntesisBoxMessage(String command, String acNum, String function, String value) {
48 this.command = command;
50 this.function = function;
54 public String getCommand() {
58 public String getFunction() {
62 public String getValue() {
66 public List<String> getLimitsValue() {
67 return Arrays.asList(value.substring(1, value.length() - 1).split(","));
70 public static @Nullable IntesisBoxMessage parse(String message) {
71 Matcher m = REGEX.matcher(message);
76 return new IntesisBoxMessage(m.group(1), m.group(2), m.group(3), m.group(4));