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