2 * Copyright (c) 2010-2022 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.util.concurrent.Executor;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
19 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaProperties.FanSpeed;
20 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
21 import org.openhab.core.util.HexUtils;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * This command sets the fanspeed for the current mode
28 * @author Benjamin Lafois - Initial contribution
32 public class SetFanspeedCommand extends BRC1HCommand {
34 private final Logger logger = LoggerFactory.getLogger(SetFanspeedCommand.class);
36 private FanSpeed coolingFanSpeed;
37 private FanSpeed heatingFanSpeed;
39 public SetFanspeedCommand(FanSpeed coolingFanSpeed, FanSpeed heatingFanSpeed) {
40 this.coolingFanSpeed = coolingFanSpeed;
41 this.heatingFanSpeed = heatingFanSpeed;
45 public byte[][] getRequest() {
46 MadokaValue paramCoolingFanSpeed = new MadokaValue(0x20, 1, new byte[] { (byte) coolingFanSpeed.value() });
47 MadokaValue paramHeatingFanSpeed = new MadokaValue(0x21, 1, new byte[] { (byte) heatingFanSpeed.value() });
49 return MadokaMessage.createRequest(this, paramCoolingFanSpeed, paramHeatingFanSpeed);
53 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm) {
54 byte[] msg = mm.getRawMessage();
55 if (logger.isDebugEnabled() && msg != null) {
56 logger.debug("Got response for {} : {}", this.getClass().getSimpleName(), HexUtils.bytesToHex(msg));
59 setState(State.SUCCEEDED);
60 executor.execute(() -> listener.receivedResponse(this));
64 public int getCommandId() {
68 public FanSpeed getCoolingFanSpeed() {
69 return coolingFanSpeed;
72 public FanSpeed getHeatingFanSpeed() {
73 return heatingFanSpeed;