]> git.basschouten.com Git - openhab-addons.git/blob
3bb730e14e4a5341c03045fd1ae42099177dc190
[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.MadokaValue;
20 import org.openhab.core.library.types.OnOffType;
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 turning on or off the AC.
27  *
28  * @author Benjamin Lafois - Initial contribution
29  *
30  */
31 @NonNullByDefault
32 public class SetPowerstateCommand extends BRC1HCommand {
33
34     private final Logger logger = LoggerFactory.getLogger(SetPowerstateCommand.class);
35
36     private OnOffType powerState;
37
38     public SetPowerstateCommand(OnOffType powerState) {
39         this.powerState = powerState;
40     }
41
42     @Override
43     public byte[][] getRequest() {
44         MadokaValue mv = new MadokaValue(0x20, 1,
45                 new byte[] { (byte) (this.powerState == OnOffType.ON ? 0x01 : 0x00) });
46
47         return MadokaMessage.createRequest(this, mv);
48     }
49
50     @Override
51     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm) {
52         byte[] msg = mm.getRawMessage();
53         if (logger.isDebugEnabled() && msg != null) {
54             logger.debug("Got response for {} : {}", this.getClass().getSimpleName(), HexUtils.bytesToHex(msg));
55         }
56
57         setState(State.SUCCEEDED);
58         executor.execute(() -> listener.receivedResponse(this));
59     }
60
61     @Override
62     public int getCommandId() {
63         return 16416;
64     }
65
66     public OnOffType getPowerState() {
67         return powerState;
68     }
69 }