]> git.basschouten.com Git - openhab-addons.git/blob
38c101c3dc374ae658d6e5ec60ec0f483d1322f8
[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 Lutron VCRX visor control receiver
28  *
29  * @author Bob Adair - Initial contribution
30  */
31 @NonNullByDefault
32 public class VcrxHandler 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
42         CCI1(30, "cci1", "CCI 1", ComponentType.CCI),
43         CCI2(31, "cci2", "CCI 2", ComponentType.CCI),
44         CCI3(32, "cci3", "CCI 3", ComponentType.CCI),
45         CCI4(33, "cci4", "CCI 4", ComponentType.CCI),
46
47         LED1(81, "led1", "LED 1", ComponentType.LED),
48         LED2(82, "led2", "LED 2", ComponentType.LED),
49         LED3(83, "led3", "LED 3", ComponentType.LED),
50         LED4(84, "led4", "LED 4", ComponentType.LED),
51         LED5(85, "led5", "LED 5", ComponentType.LED),
52         LED6(86, "led6", "LED 6", ComponentType.LED);
53
54         private final int id;
55         private final String channel;
56         private final String description;
57         private final ComponentType type;
58
59         Component(int id, String channel, String description, ComponentType type) {
60             this.id = id;
61             this.channel = channel;
62             this.description = description;
63             this.type = type;
64         }
65
66         @Override
67         public int id() {
68             return this.id;
69         }
70
71         @Override
72         public String channel() {
73             return this.channel;
74         }
75
76         @Override
77         public String description() {
78             return this.description;
79         }
80
81         @Override
82         public ComponentType type() {
83             return type;
84         }
85     }
86
87     private static final List<Component> BUTTON_GROUP = Arrays.asList(Component.BUTTON1, Component.BUTTON2,
88             Component.BUTTON3, Component.BUTTON4, Component.BUTTON5, Component.BUTTON6);
89
90     private static final List<Component> LED_GROUP = Arrays.asList(Component.LED1, Component.LED2, Component.LED3,
91             Component.LED4, Component.LED5, Component.LED6);
92
93     private static final List<Component> CCI_GROUP = Arrays.asList(Component.CCI1, Component.CCI2, Component.CCI3,
94             Component.CCI4);
95
96     private final Logger logger = LoggerFactory.getLogger(VcrxHandler.class);
97
98     @Override
99     protected boolean isLed(int id) {
100         return (id >= 81 && id <= 86);
101     }
102
103     @Override
104     protected boolean isButton(int id) {
105         return (id >= 1 && id <= 6);
106     }
107
108     @Override
109     protected boolean isCCI(int id) {
110         return (id >= 30 && id <= 33);
111     }
112
113     @Override
114     protected void configureComponents(@Nullable String model) {
115         logger.debug("Configuring components for VCRX");
116
117         buttonList.addAll(BUTTON_GROUP);
118         ledList.addAll(LED_GROUP);
119         cciList.addAll(CCI_GROUP);
120     }
121
122     public VcrxHandler(Thing thing) {
123         super(thing);
124     }
125 }