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.OperationMode;
22 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * This command returns the current AC operation mode
29 * @author Benjamin Lafois - Initial contribution
33 public class GetOperationmodeCommand extends BRC1HCommand {
35 private final Logger logger = LoggerFactory.getLogger(GetOperationmodeCommand.class);
37 private @Nullable OperationMode operationMode;
40 public byte[][] getRequest() {
41 return MadokaMessage.createRequest(this);
45 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
46 throws MadokaParsingException {
48 MadokaValue mode = mm.getValues().get(0x20);
50 setState(State.FAILED);
51 throw new MadokaParsingException("Incorrect operation mode");
53 byte[] bOperationMode = mode.getRawValue();
54 if (bOperationMode == null) {
55 setState(State.FAILED);
56 throw new MadokaParsingException("Incorrect operation mode");
59 operationMode = OperationMode.valueOf(bOperationMode[0]);
61 logger.debug("operationMode: {}", operationMode);
63 setState(State.SUCCEEDED);
65 executor.execute(() -> listener.receivedResponse(this));
66 } catch (Exception e) {
67 setState(State.FAILED);
68 throw new MadokaParsingException(e);
73 public int getCommandId() {
77 public @Nullable OperationMode getOperationMode() {