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