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.Base64;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.max.internal.Utils;
19 import org.openhab.binding.max.internal.device.ThermostatModeType;
22 * {@link SCommand} for setting MAX! thermostat temperature & mode.
24 * @author Andreas Heil (info@aheil.de) - Initial contribution
25 * @author Marcel Verpaalen - OH2 update + simplification
28 public class SCommand extends CubeCommand {
30 private static final String BASE_STRING_S = "000040000000"; // for single devices
31 private static final String BASE_STRING_G = "000440000000"; // for group/room devices
33 private final boolean[] bits;
34 private final String rfAddress;
35 private final int roomId;
38 * Creates a new instance of the MAX! protocol S command.
41 * the RF address the command is for
43 * the room ID the RF address is mapped to
44 * @param setpointTemperature
45 * the desired setpoint temperature for the device.
47 public SCommand(String rfAddress, int roomId, ThermostatModeType mode, double setpointTemperature) {
48 this.rfAddress = rfAddress;
51 // Temperature setpoint, Temp uses 6 bits (bit 0:5),
52 // 20 deg C = bits 101000 = dec 40/2 = 20 deg C,
53 // you need 8 bits to send so add the 2 bits below (sample 10101000 = hex A8)
54 // bit 0,1 = 00 = Auto weekprog (no temp is needed)
56 int setpointValue = (int) (setpointTemperature * 2);
57 bits = Utils.getBits(setpointValue);
59 // default to perm setting
67 bits[7] = false; // A (MSB)
71 bits[7] = false; // A (MSB)
75 bits[7] = true; // A (MSB)
79 // not implemented needs time
81 // no further modes supported
86 * Returns the Base64 encoded command string to be sent via the MAX!
89 * @return the string representing the command
92 public String getCommandString() {
93 final String baseString;
95 baseString = BASE_STRING_S;
97 baseString = BASE_STRING_G;
100 final String commandString = baseString + rfAddress + Utils.toHex(roomId) + Utils.toHex(bits);
102 final String encodedString = Base64.getEncoder().encodeToString(Utils.hexStringToByteArray(commandString));
104 return "s:" + encodedString + "\r\n";
108 public String getReturnStrings() {