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.nio.charset.StandardCharsets;
18 import java.util.Base64;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.max.internal.Utils;
23 import org.openhab.binding.max.internal.device.ThermostatModeType;
26 * Tests cases for {@link SCommand}.
28 * @author Marcel Verpaalen - Initial contribution
31 public class SCommandTest {
34 public void prefixTest() {
35 SCommand scmd = new SCommand("0b0da3", 1, ThermostatModeType.MANUAL, 20.0);
36 String commandStr = scmd.getCommandString();
37 String prefix = commandStr.substring(0, 2);
39 assertEquals("s:", prefix);
43 public void baseCommandTest() {
44 SCommand scmd = new SCommand("0b0da3", 1, ThermostatModeType.MANUAL, 20.0);
46 String commandStr = scmd.getCommandString();
48 String base64Data = commandStr.substring(2).trim();
49 byte[] bytes = Base64.getDecoder().decode(base64Data.getBytes(StandardCharsets.UTF_8));
51 int[] data = new int[bytes.length];
53 for (int i = 0; i < bytes.length; i++) {
54 data[i] = bytes[i] & 0xFF;
57 String decodedString = Utils.toHex(data);
58 assertEquals("s:AARAAAAACw2jAWg=\r\n", commandStr);
59 assertEquals("0004400000000B0DA30168", decodedString);
63 public void boostModeTest() {
64 SCommand scmd = new SCommand("0b0da3", 1, ThermostatModeType.BOOST, 21.0);
65 String commandStr = scmd.getCommandString();
66 assertEquals("s:AARAAAAACw2jAeo=\r\n", commandStr);
70 public void autoModeTest() {
71 SCommand scmd = new SCommand("0b0da3", 1, ThermostatModeType.AUTOMATIC, 0);
72 String commandStr = scmd.getCommandString();
73 assertEquals("s:AARAAAAACw2jAQA=\r\n", commandStr);