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.max.internal.handler;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.max.internal.command.CubeCommand;
18 import org.openhab.core.thing.ChannelUID;
19 import org.openhab.core.types.Command;
22 * Class for sending a command.
24 * @author Marcel Verpaalen - Initial contribution
27 public final class SendCommand {
30 private static int commandId = -1;
32 private @Nullable ChannelUID channelUID;
33 private @Nullable Command command;
34 private @Nullable CubeCommand cubeCommand;
35 private String serialNumber;
37 private String commandText;
39 public SendCommand(String serialNumber, ChannelUID channelUID, Command command) {
42 this.serialNumber = serialNumber;
43 this.channelUID = channelUID;
44 this.command = command;
45 key = getKey(serialNumber, channelUID);
46 this.commandText = command.toString();
49 public SendCommand(String serialNumber, CubeCommand cubeCommand, String commandText) {
52 this.serialNumber = serialNumber;
53 this.cubeCommand = cubeCommand;
54 key = getKey(serialNumber, cubeCommand);
55 this.commandText = commandText;
59 * Get the key based on the serial and channel
60 * This is can be used to find duplicated commands in the queue
62 private static String getKey(String serialNumber, ChannelUID channelUID) {
63 return serialNumber + "-" + channelUID.getId();
67 * Get the key based on the serial and channel
68 * This is can be used to find duplicated commands in the queue
70 private static String getKey(String serialNumber, CubeCommand cubeCommand) {
71 String key = serialNumber + "-" + cubeCommand.getClass().getSimpleName();
76 * @return the key based on the serial and channel
77 * This is can be used to find duplicated commands in the queue
79 public String getKey() {
87 public @Nullable ChannelUID getChannelUID() {
91 public void setChannelUID(ChannelUID channelUID) {
92 this.channelUID = channelUID;
93 key = getKey(serialNumber, channelUID);
96 public @Nullable Command getCommand() {
100 public void setCommand(Command command) {
101 this.command = command;
104 public @Nullable CubeCommand getCubeCommand() {
108 public String getDeviceSerial() {
112 public void setDeviceSerial(String device) {
113 this.serialNumber = device;
114 final ChannelUID channelUID = this.channelUID;
115 if (channelUID != null) {
116 key = getKey(serialNumber, channelUID);
120 public String getCommandText() {
124 public void setCommandText(String commandText) {
125 this.commandText = commandText;
129 public String toString() {
130 StringBuilder sb = new StringBuilder();
131 return sb.append("id: ").append(id).append(", channelUID: ").append(channelUID).append(", command: ")
132 .append(command).append(", cubeCommand: ").append(cubeCommand).append(", serialNumber: ")
133 .append(serialNumber).append(", key: ").append(key).append(", commandText: ").append(commandText)