2 * Copyright (c) 2010-2022 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 Indoor and Outdoor temperature. Outdoor is not always supported.
31 * @author Benjamin Lafois - Initial contribution
35 public class GetIndoorOutoorTemperatures extends BRC1HCommand {
37 private final Logger logger = LoggerFactory.getLogger(GetIndoorOutoorTemperatures.class);
39 private @Nullable QuantityType<Temperature> indoorTemperature;
40 private @Nullable QuantityType<Temperature> outdoorTemperature;
43 public byte[][] getRequest() {
44 return MadokaMessage.createRequest(this);
48 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
49 throws MadokaParsingException {
50 byte[] bIndoorTemperature = mm.getValues().get(0x40).getRawValue();
51 byte[] bOutdoorTemperature = mm.getValues().get(0x41).getRawValue();
53 if (bIndoorTemperature == null || bOutdoorTemperature == null) {
54 setState(State.FAILED);
55 throw new MadokaParsingException("Incorrect indoor or outdoor temperature");
58 Integer iIndoorTemperature = Integer.valueOf(bIndoorTemperature[0]);
59 Integer iOutdoorTemperature = Integer.valueOf(bOutdoorTemperature[0]);
61 if (iOutdoorTemperature == -1) {
62 iOutdoorTemperature = null;
64 if (iOutdoorTemperature < 0) {
65 iOutdoorTemperature = ((iOutdoorTemperature + 256) - 128) * -1;
69 if (iIndoorTemperature != null) {
70 indoorTemperature = new QuantityType<Temperature>(iIndoorTemperature, SIUnits.CELSIUS);
73 if (iOutdoorTemperature != null) {
74 outdoorTemperature = new QuantityType<Temperature>(iOutdoorTemperature, SIUnits.CELSIUS);
77 logger.debug("Indoor Temp: {}", indoorTemperature);
78 logger.debug("Outdoor Temp: {}", outdoorTemperature);
80 setState(State.SUCCEEDED);
81 executor.execute(() -> listener.receivedResponse(this));
84 public @Nullable QuantityType<Temperature> getIndoorTemperature() {
85 return indoorTemperature;
88 public @Nullable QuantityType<Temperature> getOutdoorTemperature() {
89 return outdoorTemperature;
93 public int getCommandId() {