]> git.basschouten.com Git - openhab-addons.git/blob
eb6aef5a7205af57973add5cfb7977e0ea5e852d
[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.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;
24
25 /**
26  * This command sets the fanspeed for the current mode
27  *
28  * @author Benjamin Lafois - Initial contribution
29  *
30  */
31 @NonNullByDefault
32 public class SetFanspeedCommand extends BRC1HCommand {
33
34     private final Logger logger = LoggerFactory.getLogger(SetFanspeedCommand.class);
35
36     private FanSpeed coolingFanSpeed;
37     private FanSpeed heatingFanSpeed;
38
39     public SetFanspeedCommand(FanSpeed coolingFanSpeed, FanSpeed heatingFanSpeed) {
40         this.coolingFanSpeed = coolingFanSpeed;
41         this.heatingFanSpeed = heatingFanSpeed;
42     }
43
44     @Override
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() });
48
49         return MadokaMessage.createRequest(this, paramCoolingFanSpeed, paramHeatingFanSpeed);
50     }
51
52     @Override
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));
57         }
58
59         setState(State.SUCCEEDED);
60         executor.execute(() -> listener.receivedResponse(this));
61     }
62
63     @Override
64     public int getCommandId() {
65         return 16464;
66     }
67
68     public FanSpeed getCoolingFanSpeed() {
69         return coolingFanSpeed;
70     }
71
72     public FanSpeed getHeatingFanSpeed() {
73         return heatingFanSpeed;
74     }
75 }