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 static org.junit.jupiter.api.Assertions.*;
17 import java.util.Base64;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.max.internal.Utils;
24 * Tests cases for {@link TCommand}.
26 * @author Marcel Verpaalen - Initial contribution
29 public class TCommandTest {
32 public void prefixTest() {
33 TCommand scmd = new TCommand("0f1d54", false);
35 String commandStr = scmd.getCommandString();
36 String prefix = commandStr.substring(0, 2);
38 assertEquals("t:", prefix);
42 public void baseCommandTest() {
43 TCommand scmd = new TCommand("0f1d54", false);
45 String commandStr = scmd.getCommandString();
47 String base64Data = commandStr.split(",")[2];
48 byte[] bytes = Base64.getDecoder().decode(base64Data.trim().getBytes());
49 int[] data = new int[bytes.length];
50 for (int i = 0; i < bytes.length; i++) {
51 data[i] = bytes[i] & 0xFF;
53 String decodedString = Utils.toHex(data);
55 assertEquals("t:01,0,Dx1U\r\n", commandStr);
56 assertEquals("0F1D54", decodedString);
60 public void addRoomTest() {
61 TCommand scmd = new TCommand("0f1d54", false);
62 scmd.addRoom("0b0da3");
64 String commandStr = scmd.getCommandString();
66 String base64Data = commandStr.split(",")[2];
67 byte[] bytes = Base64.getDecoder().decode(base64Data.trim().getBytes());
68 int[] data = new int[bytes.length];
69 for (int i = 0; i < bytes.length; i++) {
70 data[i] = bytes[i] & 0xFF;
72 String decodedString = Utils.toHex(data);
74 assertEquals("t:02,0,Cw2jDx1U\r\n", commandStr);
75 assertEquals("0B0DA30F1D54", decodedString);
79 public void forceModeTest() {
80 TCommand scmd = new TCommand("0f1d54", true);
81 String commandStr = scmd.getCommandString();
83 assertEquals("t:01,1,Dx1U\r\n", commandStr);