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.command;
15 import java.util.ArrayList;
16 import java.util.Base64;
17 import java.util.List;
19 import org.apache.commons.lang3.ArrayUtils;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.max.internal.Utils;
24 * The {@link TCommand} is used to unlink MAX! devices from the Cube.
26 * @author Marcel Verpaalen - Initial Contribution
29 public class TCommand extends CubeCommand {
31 private static final int FORCE_UPDATE = 1;
32 private static final int NO_FORCE_UPDATE = 0;
34 private final List<String> rfAddresses = new ArrayList<>();
35 private final boolean forceUpdate;
37 public TCommand(String rfAddress, boolean forceUpdate) {
38 this.rfAddresses.add(rfAddress);
39 this.forceUpdate = forceUpdate;
43 * Adds a rooms for deletion
45 public void addRoom(String rfAddress) {
46 this.rfAddresses.add(rfAddress);
50 public String getCommandString() {
51 final int updateForced = forceUpdate ? FORCE_UPDATE : NO_FORCE_UPDATE;
52 byte[] commandArray = null;
53 for (String rfAddress : rfAddresses) {
54 commandArray = ArrayUtils.addAll(Utils.hexStringToByteArray(rfAddress), commandArray);
56 String encodedString = Base64.getEncoder().encodeToString(commandArray);
58 return "t:" + String.format("%02d", rfAddresses.size()) + "," + updateForced + "," + encodedString + "\r\n";
62 public String getReturnStrings() {