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.bluetooth.daikinmadoka.internal.model.commands;
15 import java.nio.ByteBuffer;
16 import java.util.concurrent.Executor;
18 import javax.measure.quantity.Temperature;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
22 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
23 import org.openhab.core.library.types.QuantityType;
24 import org.openhab.core.util.HexUtils;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * THis command is in charge of changing the AC setpoint
31 * @author Benjamin Lafois - Initial contribution
35 public class SetSetpointCommand extends BRC1HCommand {
37 private final Logger logger = LoggerFactory.getLogger(SetSetpointCommand.class);
39 private QuantityType<Temperature> coolingSetpoint;
40 private QuantityType<Temperature> heatingSetpoint;
42 public SetSetpointCommand(QuantityType<Temperature> coolingSetpoint, QuantityType<Temperature> heatingSetpoint) {
43 this.coolingSetpoint = coolingSetpoint;
44 this.heatingSetpoint = heatingSetpoint;
48 public byte[][] getRequest() {
49 byte[] heatingSetpointBytes = ByteBuffer.allocate(2).putShort((short) (128. * heatingSetpoint.shortValue()))
51 byte[] coolingSetpointBytes = ByteBuffer.allocate(2).putShort((short) (128. * coolingSetpoint.shortValue()))
54 MadokaValue mvHeatingSetpoint = new MadokaValue(0x21, 2, heatingSetpointBytes);
56 MadokaValue mvCoolingSetpoint = new MadokaValue(0x20, 2, coolingSetpointBytes);
58 return MadokaMessage.createRequest(this, mvCoolingSetpoint, mvHeatingSetpoint);
62 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm) {
63 byte[] msg = mm.getRawMessage();
64 if (logger.isDebugEnabled() && msg != null) {
65 logger.debug("Got response for {} : {}", this.getClass().getSimpleName(), HexUtils.bytesToHex(msg));
68 setState(State.SUCCEEDED);
69 executor.execute(() -> listener.receivedResponse(this));
73 public int getCommandId() {
77 public QuantityType<Temperature> getCoolingSetpoint() {
78 return coolingSetpoint;
81 public QuantityType<Temperature> getHeatingSetpoint() {
82 return heatingSetpoint;