2 * Copyright (c) 2010-2023 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.govee.internal.command.hygrometer;
15 import java.nio.ByteBuffer;
16 import java.nio.ByteOrder;
17 import java.util.concurrent.CompletableFuture;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.core.library.types.QuantityType;
22 import org.openhab.core.library.unit.SIUnits;
23 import org.openhab.core.library.unit.Units;
26 * @author Connor Petty - Initial Contribution
30 public class GetTemHumCommand extends GetCommand {
32 private CompletableFuture<@Nullable TemHumDTO> resultHandler;
34 public GetTemHumCommand(CompletableFuture<@Nullable TemHumDTO> resultHandler) {
35 this.resultHandler = resultHandler;
39 public byte getCommandCode() {
44 public void handleResponse(byte @Nullable [] data, @Nullable Throwable th) {
46 resultHandler.completeExceptionally(th);
49 ByteBuffer buffer = ByteBuffer.wrap(data);
50 buffer.order(ByteOrder.LITTLE_ENDIAN);
51 int temp = buffer.getShort();
52 int hum = Short.toUnsignedInt(buffer.getShort());
54 TemHumDTO temhum = new TemHumDTO();
55 temhum.temperature = new QuantityType<>(temp / 100.0, SIUnits.CELSIUS);
56 temhum.humidity = new QuantityType<>(hum / 100.0, Units.PERCENT);
57 resultHandler.complete(temhum);
59 resultHandler.complete(null);