2 * Copyright (c) 2010-2020 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 org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
20 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
21 import org.openhab.core.library.types.DecimalType;
22 import org.openhab.core.util.HexUtils;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * THis command is in charge of changing the AC setpoint
29 * @author Benjamin Lafois - Initial contribution
33 public class SetSetpointCommand extends BRC1HCommand {
35 private final Logger logger = LoggerFactory.getLogger(SetSetpointCommand.class);
37 private DecimalType coolingSetpoint;
38 private DecimalType heatingSetpoint;
40 public SetSetpointCommand(DecimalType coolingSetpoint, DecimalType heatingSetpoint) {
41 this.coolingSetpoint = coolingSetpoint;
42 this.heatingSetpoint = heatingSetpoint;
46 public byte[] getRequest() {
47 byte[] heatingSetpointBytes = ByteBuffer.allocate(2).putShort((short) (128. * heatingSetpoint.shortValue()))
49 byte[] coolingSetpointBytes = ByteBuffer.allocate(2).putShort((short) (128. * coolingSetpoint.shortValue()))
52 MadokaValue mvHeatingSetpoint = new MadokaValue(0x21, 2, heatingSetpointBytes);
54 MadokaValue mvCoolingSetpoint = new MadokaValue(0x20, 2, coolingSetpointBytes);
56 return MadokaMessage.createRequest(this, mvCoolingSetpoint, mvHeatingSetpoint);
60 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm) {
61 byte[] msg = mm.getRawMessage();
62 if (logger.isDebugEnabled() && msg != null) {
63 logger.debug("Got response for {} : {}", this.getClass().getSimpleName(), HexUtils.bytesToHex(msg));
66 setState(State.SUCCEEDED);
67 executor.execute(() -> listener.receivedResponse(this));
71 public int getCommandId() {
75 public DecimalType getCoolingSetpoint() {
76 return coolingSetpoint;
79 public DecimalType getHeatingSetpoint() {
80 return heatingSetpoint;