]> git.basschouten.com Git - openhab-addons.git/blob
851a0b1d3a0bba64a9a4d473ecd429c5ae521ae8
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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 org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.lutron.internal.KeypadComponent;
18 import org.openhab.binding.lutron.internal.discovery.project.ComponentType;
19 import org.openhab.core.thing.Thing;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * Handler responsible for communicating with the virtual buttons on the RadioRA2 main repeater
25  *
26  * @author Bob Adair - Initial contribution
27  */
28 @NonNullByDefault
29 public class VirtualKeypadHandler extends BaseKeypadHandler {
30
31     private static final String MODEL_OPTION_CASETA = "Caseta";
32     private static final String MODEL_OPTION_OTHER = "Other";
33
34     private class Component implements KeypadComponent {
35         private final int id;
36         private final String channel;
37         private final String description;
38         private final ComponentType type;
39
40         Component(int id, String channel, String description, ComponentType type) {
41             this.id = id;
42             this.channel = channel;
43             this.description = description;
44             this.type = type;
45         }
46
47         @Override
48         public int id() {
49             return id;
50         }
51
52         @Override
53         public String channel() {
54             return channel;
55         }
56
57         @Override
58         public String description() {
59             return description;
60         }
61
62         @Override
63         public ComponentType type() {
64             return type;
65         }
66     }
67
68     private final Logger logger = LoggerFactory.getLogger(VirtualKeypadHandler.class);
69
70     @Override
71     protected boolean isLed(int id) {
72         return (id >= 101 && id <= 200);
73     }
74
75     @Override
76     protected boolean isButton(int id) {
77         return (id >= 1 && id <= 100);
78     }
79
80     @Override
81     protected boolean isCCI(int id) {
82         return false;
83     }
84
85     @Override
86     protected void configureComponents(@Nullable String model) {
87         String mod = model == null ? MODEL_OPTION_OTHER : model;
88         logger.debug("Configuring components for virtual keypad for model {}", mod);
89         boolean caseta = mod.equalsIgnoreCase(MODEL_OPTION_CASETA);
90
91         for (int x = 1; x <= 100; x++) {
92             buttonList.add(new Component(x, String.format("button%d", x), "Virtual Button", ComponentType.BUTTON));
93             if (!caseta) { // Caseta scene buttons have no virtual LEDs
94                 ledList.add(new Component(x + 100, String.format("led%d", x), "Virtual LED", ComponentType.LED));
95             }
96         }
97     }
98
99     public VirtualKeypadHandler(Thing thing) {
100         super(thing);
101         // Mark all channels "Advanced" since most are unlikely to be used in any particular config
102         advancedChannels = true;
103     }
104 }