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.nio.ByteOrder;
16 import java.util.concurrent.Executor;
18 import javax.measure.quantity.Time;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaMessage;
23 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaParsingException;
24 import org.openhab.binding.bluetooth.daikinmadoka.internal.model.MadokaValue;
25 import org.openhab.core.library.types.QuantityType;
26 import org.openhab.core.library.unit.Units;
27 import org.openhab.core.util.HexUtils;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * This command returns the operating hours of internal unit
34 * @author Benjamin Lafois - Initial contribution
38 public class GetOperationHoursCommand extends BRC1HCommand {
40 private final Logger logger = LoggerFactory.getLogger(GetOperationHoursCommand.class);
42 private @Nullable QuantityType<Time> indoorOperationHours;
43 private @Nullable QuantityType<Time> indoorFanHours;
44 private @Nullable QuantityType<Time> indoorPowerHours;
47 public byte[][] getRequest() {
48 MadokaValue specificUnitNumber = new MadokaValue(0x02, 1, new byte[] { (byte) 0x00 });
49 MadokaValue p40 = new MadokaValue(0x40, 0, new byte[] {});
50 MadokaValue p41 = new MadokaValue(0x41, 0, new byte[] {});
51 MadokaValue p42 = new MadokaValue(0x42, 0, new byte[] {});
52 MadokaValue p43 = new MadokaValue(0x43, 0, new byte[] {});
53 MadokaValue p44 = new MadokaValue(0x44, 0, new byte[] {});
54 MadokaValue p45 = new MadokaValue(0x45, 0, new byte[] {});
55 MadokaValue p46 = new MadokaValue(0x46, 0, new byte[] {});
56 MadokaValue p47 = new MadokaValue(0x47, 0, new byte[] {});
57 MadokaValue p48 = new MadokaValue(0x48, 0, new byte[] {});
59 return MadokaMessage.createRequest(this, specificUnitNumber, p40, p41, p42, p43, p44, p45, p46, p47, p48);
63 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
64 throws MadokaParsingException {
67 byte[] msg = mm.getRawMessage();
68 if (logger.isDebugEnabled() && msg != null) {
69 logger.debug("Got response for {} : {}", this.getClass().getSimpleName(), HexUtils.bytesToHex(msg));
72 // The specific GetOperationHours requires 2 consecutive runs for some reason.
73 // If value size is 0, then it will be for the next query!
74 if (mm.getValues().get(0x40).getSize() == 0) {
75 setState(State.SUCCEEDED);
79 Integer iIndoorOperationHours = (int) (mm.getValues().get(0x40).getComputedValue(ByteOrder.LITTLE_ENDIAN));
80 Integer iIndoorFanHours = (int) (mm.getValues().get(0x41).getComputedValue(ByteOrder.LITTLE_ENDIAN));
81 Integer iIndoorPowerHours = (int) (mm.getValues().get(0x42).getComputedValue(ByteOrder.LITTLE_ENDIAN));
83 this.indoorOperationHours = new QuantityType<Time>(iIndoorOperationHours, Units.HOUR);
84 this.indoorFanHours = new QuantityType<Time>(iIndoorFanHours, Units.HOUR);
85 this.indoorPowerHours = new QuantityType<Time>(iIndoorPowerHours, Units.HOUR);
87 logger.debug("indoorOperationHours: {}", indoorOperationHours);
88 logger.debug("indoorFanHours: {}", indoorFanHours);
89 logger.debug("indoorPowerHours: {}", indoorPowerHours);
91 setState(State.SUCCEEDED);
92 executor.execute(() -> listener.receivedResponse(this));
93 } catch (Exception e) {
94 setState(State.FAILED);
95 throw new MadokaParsingException(e);
100 public int getCommandId() {
104 public @Nullable QuantityType<Time> getIndoorOperationHours() {
105 return indoorOperationHours;
108 public @Nullable QuantityType<Time> getIndoorFanHours() {
109 return indoorFanHours;
112 public @Nullable QuantityType<Time> getIndoorPowerHours() {
113 return indoorPowerHours;