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.util.concurrent.TimeUnit;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.bluetooth.gattserial.SimpleMessageServicer;
22 * @author Connor Petty - Initial Contribution
26 public abstract class GoveeCommand implements SimpleMessageServicer<GoveeMessage> {
28 public static final byte READ_TYPE = -86;
29 public static final byte WRITE_TYPE = 51;
31 public abstract byte getCommandType();
33 public abstract byte getCommandCode();
35 protected abstract byte @Nullable [] getData();
38 public long getTimeout(TimeUnit unit) {
39 return unit.convert(60, TimeUnit.SECONDS);
43 public GoveeMessage createMessage() {
44 return new GoveeMessage(getCommandType(), getCommandCode(), getData());
48 public boolean handleFailedMessage(GoveeMessage message, Throwable th) {
49 if (matches(message)) {
50 handleResponse(null, th);
57 public boolean handleReceivedMessage(GoveeMessage message) {
58 if (matches(message)) {
59 handleResponse(message.getData(), null);
65 public abstract void handleResponse(byte @Nullable [] data, @Nullable Throwable th);
67 protected boolean matches(GoveeMessage message) {
68 return message.getCommandType() == getCommandType() && message.getCommandCode() == getCommandCode();