2 * Copyright (c) 2010-2020 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 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;
26 * This command returns the setpoint, whatever is the current mode.
28 * @author Benjamin Lafois - Initial contribution
32 public class GetSetpointCommand extends BRC1HCommand {
34 private final Logger logger = LoggerFactory.getLogger(GetSetpointCommand.class);
36 private @Nullable DecimalType heatingSetpoint;
37 private @Nullable DecimalType coolingSetpoint;
40 public byte[] getRequest() {
41 return MadokaMessage.createRequest(this);
45 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
46 throws MadokaParsingException {
48 Integer iHeatingSetpoint = (int) (mm.getValues().get(0x21).getComputedValue() / 128.);
49 Integer iCoolingSetpoint = (int) (mm.getValues().get(0x20).getComputedValue() / 128.);
51 this.heatingSetpoint = new DecimalType(iHeatingSetpoint);
52 this.coolingSetpoint = new DecimalType(iCoolingSetpoint);
54 logger.debug("heatingSetpoint: {}", heatingSetpoint);
55 logger.debug("coolingSetpoint: {}", coolingSetpoint);
57 setState(State.SUCCEEDED);
58 executor.execute(() -> listener.receivedResponse(this));
59 } catch (Exception e) {
60 setState(State.FAILED);
61 throw new MadokaParsingException(e);
66 public int getCommandId() {
70 public @Nullable DecimalType getHeatingSetpoint() {
71 return heatingSetpoint;
74 public @Nullable DecimalType getCoolingSetpoint() {
75 return coolingSetpoint;