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