2 * Copyright (c) 2010-2024 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.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * This command returns the operating hours of internal unit
33 * @author Benjamin Lafois - Initial contribution
37 public class GetOperationHoursCommand extends BRC1HCommand {
39 private final Logger logger = LoggerFactory.getLogger(GetOperationHoursCommand.class);
41 private @Nullable QuantityType<Time> indoorOperationHours;
42 private @Nullable QuantityType<Time> indoorFanHours;
43 private @Nullable QuantityType<Time> indoorPowerHours;
46 public byte[][] getRequest() {
47 MadokaValue specificUnitNumber = new MadokaValue(0x02, 1, new byte[] { (byte) 0x00 });
48 MadokaValue p40 = new MadokaValue(0x40, 0, new byte[] {});
49 MadokaValue p41 = new MadokaValue(0x41, 0, new byte[] {});
50 MadokaValue p42 = new MadokaValue(0x42, 0, new byte[] {});
51 MadokaValue p43 = new MadokaValue(0x43, 0, new byte[] {});
52 MadokaValue p44 = new MadokaValue(0x44, 0, new byte[] {});
53 MadokaValue p45 = new MadokaValue(0x45, 0, new byte[] {});
54 MadokaValue p46 = new MadokaValue(0x46, 0, new byte[] {});
55 MadokaValue p47 = new MadokaValue(0x47, 0, new byte[] {});
56 MadokaValue p48 = new MadokaValue(0x48, 0, new byte[] {});
58 return MadokaMessage.createRequest(this, specificUnitNumber, p40, p41, p42, p43, p44, p45, p46, p47, p48);
62 public void handleResponse(Executor executor, ResponseListener listener, MadokaMessage mm)
63 throws MadokaParsingException {
64 MadokaValue opHours = mm.getValues().get(0x40);
65 MadokaValue fanHours = mm.getValues().get(0x41);
66 MadokaValue powerHours = mm.getValues().get(0x42);
67 if (opHours == null || fanHours == null || powerHours == null) {
68 String message = "indoorOperationHours, indoorFanHours or indoorPowerHours is null when handling the response";
69 setState(State.FAILED);
70 throw new MadokaParsingException(message);
73 if (opHours.getSize() == 0) {
74 setState(State.SUCCEEDED);
78 Integer iIndoorOperationHours = (int) (opHours.getComputedValue(ByteOrder.LITTLE_ENDIAN));
79 Integer iIndoorFanHours = (int) (fanHours.getComputedValue(ByteOrder.LITTLE_ENDIAN));
80 Integer iIndoorPowerHours = (int) (powerHours.getComputedValue(ByteOrder.LITTLE_ENDIAN));
82 this.indoorOperationHours = new QuantityType<Time>(iIndoorOperationHours, Units.HOUR);
83 this.indoorFanHours = new QuantityType<Time>(iIndoorFanHours, Units.HOUR);
84 this.indoorPowerHours = new QuantityType<Time>(iIndoorPowerHours, Units.HOUR);
86 logger.debug("indoorOperationHours: {}", indoorOperationHours);
87 logger.debug("indoorFanHours: {}", indoorFanHours);
88 logger.debug("indoorPowerHours: {}", indoorPowerHours);
90 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;