]> git.basschouten.com Git - openhab-addons.git/blob
ce4a984b49ef940cc15dd51e0a807dcb8c85a13a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.max.internal.command;
14
15 import java.util.ArrayList;
16 import java.util.Base64;
17 import java.util.List;
18
19 import org.apache.commons.lang3.ArrayUtils;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.max.internal.Utils;
22
23 /**
24  * The {@link TCommand} is used to unlink MAX! devices from the Cube.
25  *
26  * @author Marcel Verpaalen - Initial Contribution
27  */
28 @NonNullByDefault
29 public class TCommand extends CubeCommand {
30
31     private static final int FORCE_UPDATE = 1;
32     private static final int NO_FORCE_UPDATE = 0;
33
34     private final List<String> rfAddresses = new ArrayList<>();
35     private final boolean forceUpdate;
36
37     public TCommand(String rfAddress, boolean forceUpdate) {
38         this.rfAddresses.add(rfAddress);
39         this.forceUpdate = forceUpdate;
40     }
41
42     /**
43      * Adds a rooms for deletion
44      */
45     public void addRoom(String rfAddress) {
46         this.rfAddresses.add(rfAddress);
47     }
48
49     @Override
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);
55         }
56         String encodedString = Base64.getEncoder().encodeToString(commandArray);
57
58         return "t:" + String.format("%02d", rfAddresses.size()) + "," + updateForced + "," + encodedString + "\r\n";
59     }
60
61     @Override
62     public String getReturnStrings() {
63         return "A:";
64     }
65 }