2 * Copyright (c) 2010-2023 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.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
24 import org.openhab.core.library.types.QuantityType;
25 import org.openhab.core.library.unit.SIUnits;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * This command returns the setpoint, whatever is the current mode.
32 * @author Benjamin Lafois - Initial contribution
36 public class GetSetpointCommand extends BRC1HCommand {
38 private final Logger logger = LoggerFactory.getLogger(GetSetpointCommand.class);
40 private @Nullable QuantityType<Temperature> heatingSetpoint;
41 private @Nullable QuantityType<Temperature> coolingSetpoint;
44 public byte[][] getRequest() {
45 return MadokaMessage.createRequest(this);
49 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
50 throws MadokaParsingException {
51 MadokaValue heatValue = mm.getValues().get(0x21);
52 MadokaValue coolValue = mm.getValues().get(0x20);
53 if (heatValue == null || coolValue == null) {
54 String message = "heatingSetpoint or coolingSetpoint is null when handling the response";
55 setState(State.FAILED);
56 throw new MadokaParsingException(message);
59 Integer iHeatingSetpoint = (int) (heatValue.getComputedValue() / 128.);
60 Integer iCoolingSetpoint = (int) (coolValue.getComputedValue() / 128.);
62 this.heatingSetpoint = new QuantityType<Temperature>(iHeatingSetpoint, SIUnits.CELSIUS);
63 this.coolingSetpoint = new QuantityType<Temperature>(iCoolingSetpoint, SIUnits.CELSIUS);
65 logger.debug("heatingSetpoint: {}", heatingSetpoint);
66 logger.debug("coolingSetpoint: {}", coolingSetpoint);
68 setState(State.SUCCEEDED);
70 executor.execute(() -> listener.receivedResponse(this));
71 } catch (Exception e) {
72 setState(State.FAILED);
73 throw new MadokaParsingException(e);
78 public int getCommandId() {
82 public @Nullable QuantityType<Temperature> getHeatingSetpoint() {
83 return heatingSetpoint;
86 public @Nullable QuantityType<Temperature> getCoolingSetpoint() {
87 return coolingSetpoint;