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.util.concurrent.Executor;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
20 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingException;
21 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaProperties.FanSpeed;
22 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Command used to set the FAN speed for all modes (auto/cool/heat...)
29 * @author Benjamin Lafois - Initial contribution
33 public class GetFanspeedCommand extends BRC1HCommand {
35 private final Logger logger = LoggerFactory.getLogger(GetFanspeedCommand.class);
37 private @Nullable FanSpeed coolingFanSpeed;
38 private @Nullable FanSpeed heatingFanSpeed;
41 public byte[][] getRequest() {
42 return MadokaMessage.createRequest(this);
46 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
47 throws MadokaParsingException {
48 MadokaValue coolValue = mm.getValues().get(0x20);
49 MadokaValue heatValue = mm.getValues().get(0x21);
50 if (heatValue == null || coolValue == null) {
51 String message = "heating or cooling fan speed is null when handling the response";
52 setState(State.FAILED);
53 throw new MadokaParsingException(message);
56 byte[] valueCoolingFanSpeed = coolValue.getRawValue();
57 byte[] valueHeatingFanSpeed = heatValue.getRawValue();
59 if (valueCoolingFanSpeed == null || valueHeatingFanSpeed == null) {
60 setState(State.FAILED);
61 throw new MadokaParsingException("Incorrect cooling or heating fan speed value");
64 this.coolingFanSpeed = FanSpeed.valueOf(valueCoolingFanSpeed[0]);
65 this.heatingFanSpeed = FanSpeed.valueOf(valueHeatingFanSpeed[0]);
67 logger.debug("coolingFanSpeed: {}", coolingFanSpeed);
68 logger.debug("heatingFanSpeed: {}", heatingFanSpeed);
70 setState(State.SUCCEEDED);
73 executor.execute(() -> listener.receivedResponse(this));
74 } catch (Exception e) {
75 setState(State.FAILED);
76 throw new MadokaParsingException(e);
81 public int getCommandId() {
85 public @Nullable FanSpeed getCoolingFanSpeed() {
86 return coolingFanSpeed;
89 public @Nullable FanSpeed getHeatingFanSpeed() {
90 return heatingFanSpeed;