]> git.basschouten.com Git - openhab-addons.git/blob
96ec6eb93f04b92a0d301a4196dc5aeac7f64500
[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.nio.ByteBuffer;
16 import java.util.concurrent.Executor;
17
18 import javax.measure.quantity.Temperature;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
22 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
23 import org.openhab.core.library.types.QuantityType;
24 import org.openhab.core.util.HexUtils;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 /**
29  * THis command is in charge of changing the AC setpoint
30  *
31  * @author Benjamin Lafois - Initial contribution
32  *
33  */
34 @NonNullByDefault
35 public class SetSetpointCommand extends BRC1HCommand {
36
37     private final Logger logger = LoggerFactory.getLogger(SetSetpointCommand.class);
38
39     private QuantityType<Temperature> coolingSetpoint;
40     private QuantityType<Temperature> heatingSetpoint;
41
42     public SetSetpointCommand(QuantityType<Temperature> coolingSetpoint, QuantityType<Temperature> heatingSetpoint) {
43         this.coolingSetpoint = coolingSetpoint;
44         this.heatingSetpoint = heatingSetpoint;
45     }
46
47     @Override
48     public byte[][] getRequest() {
49         byte[] heatingSetpointBytes = ByteBuffer.allocate(2).putShort((short) (128. * heatingSetpoint.shortValue()))
50                 .array();
51         byte[] coolingSetpointBytes = ByteBuffer.allocate(2).putShort((short) (128. * coolingSetpoint.shortValue()))
52                 .array();
53
54         MadokaValue mvHeatingSetpoint = new MadokaValue(0x21, 2, heatingSetpointBytes);
55
56         MadokaValue mvCoolingSetpoint = new MadokaValue(0x20, 2, coolingSetpointBytes);
57
58         return MadokaMessage.createRequest(this, mvCoolingSetpoint, mvHeatingSetpoint);
59     }
60
61     @Override
62     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm) {
63         byte[] msg = mm.getRawMessage();
64         if (logger.isDebugEnabled() && msg != null) {
65             logger.debug("Got response for {} : {}", this.getClass().getSimpleName(), HexUtils.bytesToHex(msg));
66         }
67
68         setState(State.SUCCEEDED);
69         executor.execute(() -> listener.receivedResponse(this));
70     }
71
72     @Override
73     public int getCommandId() {
74         return 16448;
75     }
76
77     public QuantityType<Temperature> getCoolingSetpoint() {
78         return coolingSetpoint;
79     }
80
81     public QuantityType<Temperature> getHeatingSetpoint() {
82         return heatingSetpoint;
83     }
84 }