]> git.basschouten.com Git - openhab-addons.git/blob
cdab0749a1de02a3f900852213f5c5c56d0c5f4f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.lutron.internal.radiora.protocol;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  * Button Press (BP) Command.
23  * Trigger a Phantom Button Press on the RadioRA Serial Device.
24  *
25  * @author Jeff Lauterbach - Initial Contribution
26  *
27  */
28 @NonNullByDefault
29 public class ButtonPressCommand extends RadioRACommand {
30
31     public enum ButtonState {
32         OFF,
33         ON,
34         TOG
35     }
36
37     private int buttonNumber; // 1 to 15, 16 ALL ON, 17 ALL OFF
38     private ButtonState state; // ON/OFF/TOG
39     private @Nullable Integer fadeSec; // 0 to 240 (optional)
40     private int system; // 1 or 2, or 0 for none
41
42     public ButtonPressCommand(int buttonNumber, ButtonState state, int system) {
43         this.buttonNumber = buttonNumber;
44         this.state = state;
45         this.system = system;
46     }
47
48     public void setFadeSeconds(int seconds) {
49         this.fadeSec = seconds;
50     }
51
52     @Override
53     public String getCommand() {
54         return "BP";
55     }
56
57     @Override
58     public List<String> getArgs() {
59         List<String> args = new ArrayList<>();
60         args.add(String.valueOf(buttonNumber));
61         args.add(String.valueOf(state));
62
63         if (fadeSec != null) {
64             args.add(String.valueOf(fadeSec));
65         }
66
67         if (system == 1 || system == 2) {
68             args.add("S" + String.valueOf(system));
69         }
70
71         return args;
72     }
73 }