]> git.basschouten.com Git - openhab-addons.git/blob
4f2cfd6bde67c47156f3147c3d73d54ce0f40c9b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.Map.Entry;
16 import java.util.stream.Collectors;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.lutron.internal.discovery.project.ComponentType;
21 import org.openhab.binding.lutron.internal.keypadconfig.KeypadConfigPico;
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 Pico keypads
28  *
29  * @author Bob Adair - Initial contribution
30  */
31 @NonNullByDefault
32 public class PicoKeypadHandler extends BaseKeypadHandler {
33
34     private final Logger logger = LoggerFactory.getLogger(PicoKeypadHandler.class);
35
36     public PicoKeypadHandler(Thing thing) {
37         super(thing);
38         kp = new KeypadConfigPico();
39     }
40
41     @Override
42     protected void configureComponents(@Nullable String model) {
43         String mod = model == null ? "Generic" : model;
44         logger.debug("Configuring components for keypad model {}", mod);
45
46         switch (mod) {
47             case "2B":
48                 buttonList = kp.getComponents(mod, ComponentType.BUTTON);
49                 leapButtonMap = KeypadConfigPico.LEAPBUTTONS_2B;
50                 break;
51             case "2BRL":
52                 buttonList = kp.getComponents(mod, ComponentType.BUTTON);
53                 leapButtonMap = KeypadConfigPico.LEAPBUTTONS_2BRL;
54                 break;
55             case "3B":
56                 buttonList = kp.getComponents(mod, ComponentType.BUTTON);
57                 leapButtonMap = KeypadConfigPico.LEAPBUTTONS_3B;
58                 break;
59             case "4B":
60                 buttonList = kp.getComponents(mod, ComponentType.BUTTON);
61                 leapButtonMap = KeypadConfigPico.LEAPBUTTONS_4B;
62                 break;
63             default:
64                 logger.warn("No valid keypad model defined ({}). Assuming model 3BRL.", mod);
65                 // fall through
66             case "Generic":
67             case "3BRL":
68                 buttonList = kp.getComponents("3BRL", ComponentType.BUTTON);
69                 leapButtonMap = KeypadConfigPico.LEAPBUTTONS_3BRL;
70                 break;
71         }
72         leapButtonInverseMap = leapButtonMap.entrySet().stream()
73                 .collect(Collectors.toMap(Entry::getValue, Entry::getKey));
74     }
75 }