]> git.basschouten.com Git - openhab-addons.git/blob
3f2e88ce6cfbdd55f2fc0a8a75af54d864914c96
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands;
14
15 import java.util.concurrent.Executor;
16
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.OperationMode;
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;
24
25 /**
26  * This command is in charge of changing the current operation mode
27  *
28  * @author Benjamin Lafois - Initial contribution
29  *
30  */
31 @NonNullByDefault
32 public class SetOperationmodeCommand extends BRC1HCommand {
33
34     private final Logger logger = LoggerFactory.getLogger(SetOperationmodeCommand.class);
35
36     private OperationMode operationMode;
37
38     public SetOperationmodeCommand(OperationMode operationMode) {
39         this.operationMode = operationMode;
40     }
41
42     @Override
43     public byte[][] getRequest() {
44         MadokaValue mv = new MadokaValue(0x20, 1, new byte[] { (byte) this.operationMode.value() });
45         return MadokaMessage.createRequest(this, mv);
46     }
47
48     @Override
49     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm) {
50         byte[] msg = mm.getRawMessage();
51         if (logger.isDebugEnabled() && msg != null) {
52             logger.debug("Got response for {} : {}", this.getClass().getSimpleName(), HexUtils.bytesToHex(msg));
53         }
54
55         setState(State.SUCCEEDED);
56         executor.execute(() -> listener.receivedResponse(this));
57     }
58
59     @Override
60     public int getCommandId() {
61         return 16432;
62     }
63
64     public OperationMode getOperationMode() {
65         return operationMode;
66     }
67 }