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.luxom.internal.protocol;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
21 * @author Kris Jespers - Initial contribution
24 public class LuxomCommand {
25 private final LuxomAction action;
26 private final @Nullable String address; // must for data byte commands be set after construction
28 private @Nullable String data;
30 public LuxomCommand(String command) {
31 if (command.length() == 0) {
32 action = LuxomAction.INVALID_ACTION;
37 String[] parts = command.split(",");
39 if (parts.length == 1) {
40 if (command.startsWith(LuxomAction.MODULE_INFORMATION.getCommand())) {
41 action = LuxomAction.MODULE_INFORMATION;
42 data = command.substring(2);
43 } else if (command.equals(LuxomAction.PASSWORD_REQUEST.getCommand())) {
44 action = LuxomAction.PASSWORD_REQUEST;
46 } else if (command.equals(LuxomAction.ACKNOWLEDGE.getCommand())) {
47 action = LuxomAction.ACKNOWLEDGE;
50 action = LuxomAction.INVALID_ACTION;
55 action = LuxomAction.of(parts[0]);
56 StringBuilder stringBuilder = new StringBuilder();
57 if (action.isHasAddress()) {
58 // first 0 not needed ?
59 for (int i = 2; i < parts.length; i++) {
60 stringBuilder.append(parts[i]);
61 if (i != (parts.length - 1)) {
62 stringBuilder.append(",");
65 address = stringBuilder.toString();
68 for (int i = 1; i < parts.length; i++) {
69 stringBuilder.append(parts[i]);
70 if (i != (parts.length - 1)) {
71 stringBuilder.append(",");
75 data = stringBuilder.toString();
81 public String toString() {
82 return "LuxomCommand{" + "action=" + action + ", address='" + address + '\'' + ", data='" + data + '\'' + '}';
85 public LuxomAction getAction() {
90 public String getData() {
95 public String getAddress() {
99 public void setData(@Nullable String data) {