2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bluetooth.daikinmadoka.internal.model.commands;
15 import java.util.concurrent.Executor;
17 import javax.measure.quantity.Temperature;
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;
29 * This command returns the setpoint, whatever is the current mode.
31 * @author Benjamin Lafois - Initial contribution
35 public class GetSetpointCommand extends BRC1HCommand {
37 private final Logger logger = LoggerFactory.getLogger(GetSetpointCommand.class);
39 private @Nullable QuantityType<Temperature> heatingSetpoint;
40 private @Nullable QuantityType<Temperature> coolingSetpoint;
43 public byte[][] getRequest() {
44 return MadokaMessage.createRequest(this);
48 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
49 throws MadokaParsingException {
51 Integer iHeatingSetpoint = (int) (mm.getValues().get(0x21).getComputedValue() / 128.);
52 Integer iCoolingSetpoint = (int) (mm.getValues().get(0x20).getComputedValue() / 128.);
54 this.heatingSetpoint = new QuantityType<Temperature>(iHeatingSetpoint, SIUnits.CELSIUS);
55 this.coolingSetpoint = new QuantityType<Temperature>(iCoolingSetpoint, SIUnits.CELSIUS);
57 logger.debug("heatingSetpoint: {}", heatingSetpoint);
58 logger.debug("coolingSetpoint: {}", coolingSetpoint);
60 setState(State.SUCCEEDED);
61 executor.execute(() -> listener.receivedResponse(this));
62 } catch (Exception e) {
63 setState(State.FAILED);
64 throw new MadokaParsingException(e);
69 public int getCommandId() {
73 public @Nullable QuantityType<Temperature> getHeatingSetpoint() {
74 return heatingSetpoint;
77 public @Nullable QuantityType<Temperature> getCoolingSetpoint() {
78 return coolingSetpoint;