]> git.basschouten.com Git - openhab-addons.git/blob
07d7fcf57505c3d771fa5ec2f85604498dca34da
[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 GetLightLevelCommand} is used to get the current light sensor reading.
22  *
23  * @author Connor Petty - Initial contribution
24  */
25 @NonNullByDefault
26 public class GetLightLevelCommand extends AM43Command {
27
28     private static final byte COMMAND = (byte) 0xaa;
29
30     public GetLightLevelCommand() {
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 getLightLevel() {
44         return getResponse()[4];
45     }
46
47     @Override
48     public int minResponseSize() {
49         return 6;
50     }
51 }