]> git.basschouten.com Git - openhab-addons.git/blob
64993f44441bcf937cdd88398be6d7a24df4bc81
[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 import org.openhab.binding.bluetooth.am43.internal.data.Direction;
20 import org.openhab.binding.bluetooth.am43.internal.data.OperationMode;
21
22 /**
23  * The {@link GetAllCommand} gets the bulk of the settings on AM43.
24  * A GetAllCommand request actually returns several responses. But we are
25  * only interested in the device settings response (which luckily has the same command header as the request).
26  *
27  * @author Connor Petty - Initial contribution
28  */
29 @NonNullByDefault
30 public class GetAllCommand extends AM43Command {
31
32     private static final byte COMMAND = (byte) 0xa7;
33
34     public GetAllCommand() {
35         super(COMMAND, (byte) 1);
36     }
37
38     @Override
39     public boolean handleResponse(Executor executor, ResponseListener listener, byte @Nullable [] response) {
40         if (super.handleResponse(executor, listener, response)) {
41             executor.execute(() -> listener.receivedResponse(this));
42             return true;
43         }
44         return false;
45     }
46
47     public Direction getDirection() {
48         return Direction.valueOf((getResponse()[3] & 1) > 0);
49     }
50
51     public OperationMode getOperationMode() {
52         return OperationMode.valueOf((getResponse()[3] & 2) > 0);
53     }
54
55     public boolean getTopLimitSet() {
56         return (getResponse()[3] & 4) > 0;
57     }
58
59     public boolean getBottomLimitSet() {
60         return (getResponse()[3] & 8) > 0;
61     }
62
63     public boolean getHasLightSensor() {
64         return (getResponse()[3] & 16) > 0;
65     }
66
67     public int getSpeed() {
68         return getResponse()[4];
69     }
70
71     public int getPosition() {
72         return getResponse()[5];
73     }
74
75     public int getLength() {
76         return getResponse()[6] << 8 | getResponse()[7];
77     }
78
79     public int getDiameter() {
80         return getResponse()[8];
81     }
82
83     public int getType() {
84         return Math.abs(getResponse()[9] >> 4);
85     }
86
87     @Override
88     public int minResponseSize() {
89         return 10;
90     }
91 }