]> git.basschouten.com Git - openhab-addons.git/blob
7c1aae9a121e66d5bb0993e381697bbd7b740f31
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.bluetooth.am43.internal.command;
14
15 import java.util.concurrent.Executor;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 /**
21  * The {@link GetBatteryLevelCommand} is used to get the current battery level of the AM43.
22  *
23  * @author Connor Petty - Initial contribution
24  */
25 @NonNullByDefault
26 public class GetBatteryLevelCommand extends AM43Command {
27
28     private static final byte COMMAND = (byte) 0xa2;
29
30     public GetBatteryLevelCommand() {
31         super(COMMAND, (byte) 1);
32     }
33
34     @Override
35     public boolean handleResponse(Executor executor, ResponseListener listener, byte @Nullable [] response) {
36         if (super.handleResponse(executor, listener, response)) {
37             executor.execute(() -> listener.receivedResponse(this));
38             return true;
39         }
40         return false;
41     }
42
43     public int getBatteryLevel() {
44         return getResponse()[7];
45     }
46
47     @Override
48     public int minResponseSize() {
49         return 9;
50     }
51 }