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 return serialNumber + "-" + cubeCommand.getClass().getSimpleName();
75 * @return the key based on the serial and channel
76 * This is can be used to find duplicated commands in the queue
78 public String getKey() {
86 public @Nullable ChannelUID getChannelUID() {
90 public void setChannelUID(ChannelUID channelUID) {
91 this.channelUID = channelUID;
92 key = getKey(serialNumber, channelUID);
95 public @Nullable Command getCommand() {
99 public void setCommand(Command command) {
100 this.command = command;
103 public @Nullable CubeCommand getCubeCommand() {
107 public String getDeviceSerial() {
111 public void setDeviceSerial(String device) {
112 this.serialNumber = device;
113 final ChannelUID channelUID = this.channelUID;
114 if (channelUID != null) {
115 key = getKey(serialNumber, channelUID);
119 public String getCommandText() {
123 public void setCommandText(String commandText) {
124 this.commandText = commandText;
128 public String toString() {
129 StringBuilder sb = new StringBuilder();
130 return sb.append("id: ").append(id).append(", channelUID: ").append(channelUID).append(", command: ")
131 .append(command).append(", cubeCommand: ").append(cubeCommand).append(", serialNumber: ")
132 .append(serialNumber).append(", key: ").append(key).append(", commandText: ").append(commandText)