]> git.basschouten.com Git - openhab-addons.git/blob
424f554e45a79a20a9c60bca4e13acd8236ab3a9
[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.util.concurrent.Executor;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
20 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingException;
21 import org.openhab.core.library.types.DecimalType;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * This command returns the setpoint, whatever is the current mode.
27  *
28  * @author Benjamin Lafois - Initial contribution
29  *
30  */
31 @NonNullByDefault
32 public class GetSetpointCommand extends BRC1HCommand {
33
34     private final Logger logger = LoggerFactory.getLogger(GetSetpointCommand.class);
35
36     private @Nullable DecimalType heatingSetpoint;
37     private @Nullable DecimalType coolingSetpoint;
38
39     @Override
40     public byte[] getRequest() {
41         return MadokaMessage.createRequest(this);
42     }
43
44     @Override
45     public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
46             throws MadokaParsingException {
47         try {
48             Integer iHeatingSetpoint = (int) (mm.getValues().get(0x21).getComputedValue() / 128.);
49             Integer iCoolingSetpoint = (int) (mm.getValues().get(0x20).getComputedValue() / 128.);
50
51             this.heatingSetpoint = new DecimalType(iHeatingSetpoint);
52             this.coolingSetpoint = new DecimalType(iCoolingSetpoint);
53
54             logger.debug("heatingSetpoint: {}", heatingSetpoint);
55             logger.debug("coolingSetpoint: {}", coolingSetpoint);
56
57             setState(State.SUCCEEDED);
58             executor.execute(() -> listener.receivedResponse(this));
59         } catch (Exception e) {
60             setState(State.FAILED);
61             throw new MadokaParsingException(e);
62         }
63     }
64
65     @Override
66     public int getCommandId() {
67         return 64;
68     }
69
70     public @Nullable DecimalType getHeatingSetpoint() {
71         return heatingSetpoint;
72     }
73
74     public @Nullable DecimalType getCoolingSetpoint() {
75         return coolingSetpoint;
76     }
77 }