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 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 Indoor and Outdoor temperature. Outdoor is not always supported.
28 * @author Benjamin Lafois - Initial contribution
32 public class GetIndoorOutoorTemperatures extends BRC1HCommand {
34 private final Logger logger = LoggerFactory.getLogger(GetIndoorOutoorTemperatures.class);
36 private @Nullable DecimalType indoorTemperature;
37 private @Nullable DecimalType outdoorTemperature;
40 public byte[] getRequest() {
41 return MadokaMessage.createRequest(this);
45 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
46 throws MadokaParsingException {
47 byte[] bIndoorTemperature = mm.getValues().get(0x40).getRawValue();
48 byte[] bOutdoorTemperature = mm.getValues().get(0x41).getRawValue();
50 if (bIndoorTemperature == null || bOutdoorTemperature == null) {
51 setState(State.FAILED);
52 throw new MadokaParsingException("Incorrect indoor or outdoor temperature");
55 Integer iIndoorTemperature = Integer.valueOf(bIndoorTemperature[0]);
56 Integer iOutdoorTemperature = Integer.valueOf(bOutdoorTemperature[0]);
58 if (iOutdoorTemperature == -1) {
59 iOutdoorTemperature = null;
61 if (iOutdoorTemperature < 0) {
62 iOutdoorTemperature = ((iOutdoorTemperature + 256) - 128) * -1;
66 if (iIndoorTemperature != null) {
67 indoorTemperature = new DecimalType(iIndoorTemperature);
70 if (iOutdoorTemperature != null) {
71 outdoorTemperature = new DecimalType(iOutdoorTemperature);
74 logger.debug("Indoor Temp: {}", indoorTemperature);
75 logger.debug("Outdoor Temp: {}", outdoorTemperature);
77 setState(State.SUCCEEDED);
78 executor.execute(() -> listener.receivedResponse(this));
81 public @Nullable DecimalType getIndoorTemperature() {
82 return indoorTemperature;
85 public @Nullable DecimalType getOutdoorTemperature() {
86 return outdoorTemperature;
90 public int getCommandId() {