]> git.basschouten.com Git - openhab-addons.git/blob
f3fabb631c28aa772aa656902643032f387cb1c3
[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.lutron.internal.handler;
14
15 import java.util.Arrays;
16 import java.util.List;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.lutron.internal.KeypadComponent;
21 import org.openhab.binding.lutron.internal.discovery.project.ComponentType;
22 import org.openhab.core.thing.Thing;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * Handler responsible for communicating with the Lutron Wallbox Input Closure Interface (WCI)
28  *
29  * @author Bob Adair - Initial contribution
30  */
31 @NonNullByDefault
32 public class WciHandler extends BaseKeypadHandler {
33
34     private static enum Component implements KeypadComponent {
35         BUTTON1(1, "button1", "Button 1", ComponentType.BUTTON),
36         BUTTON2(2, "button2", "Button 2", ComponentType.BUTTON),
37         BUTTON3(3, "button3", "Button 3", ComponentType.BUTTON),
38         BUTTON4(4, "button4", "Button 4", ComponentType.BUTTON),
39         BUTTON5(5, "button5", "Button 5", ComponentType.BUTTON),
40         BUTTON6(6, "button6", "Button 6", ComponentType.BUTTON),
41         BUTTON7(7, "button7", "Button 7", ComponentType.BUTTON),
42         BUTTON8(8, "button8", "Button 8", ComponentType.BUTTON),
43
44         LED1(81, "led1", "LED 1", ComponentType.LED),
45         LED2(82, "led2", "LED 2", ComponentType.LED),
46         LED3(83, "led3", "LED 3", ComponentType.LED),
47         LED4(84, "led4", "LED 4", ComponentType.LED),
48         LED5(85, "led5", "LED 5", ComponentType.LED),
49         LED6(86, "led6", "LED 6", ComponentType.LED),
50         LED7(87, "led7", "LED 7", ComponentType.LED),
51         LED8(88, "led8", "LED 8", ComponentType.LED);
52
53         private final int id;
54         private final String channel;
55         private final String description;
56         private final ComponentType type;
57
58         Component(int id, String channel, String description, ComponentType type) {
59             this.id = id;
60             this.channel = channel;
61             this.description = description;
62             this.type = type;
63         }
64
65         @Override
66         public int id() {
67             return this.id;
68         }
69
70         @Override
71         public String channel() {
72             return this.channel;
73         }
74
75         @Override
76         public String description() {
77             return this.description;
78         }
79
80         @Override
81         public ComponentType type() {
82             return type;
83         }
84     }
85
86     private static final List<KeypadComponent> BUTTON_LIST = Arrays.asList(Component.BUTTON1, Component.BUTTON2,
87             Component.BUTTON3, Component.BUTTON4, Component.BUTTON5, Component.BUTTON6, Component.BUTTON7,
88             Component.BUTTON8);
89
90     private static final List<KeypadComponent> LED_LIST = Arrays.asList(Component.LED1, Component.LED2, Component.LED3,
91             Component.LED4, Component.LED5, Component.LED6, Component.LED7, Component.LED8);
92
93     private final Logger logger = LoggerFactory.getLogger(WciHandler.class);
94
95     @Override
96     protected boolean isLed(int id) {
97         return (id >= 81 && id <= 88);
98     }
99
100     @Override
101     protected boolean isButton(int id) {
102         return (id >= 1 && id <= 8);
103     }
104
105     @Override
106     protected boolean isCCI(int id) {
107         return false;
108     }
109
110     @Override
111     protected void configureComponents(@Nullable String model) {
112         logger.trace("Configuring components for WCI");
113
114         buttonList.addAll(BUTTON_LIST);
115         ledList.addAll(LED_LIST);
116     }
117
118     public WciHandler(Thing thing) {
119         super(thing);
120     }
121 }