]> git.basschouten.com Git - openhab-addons.git/blob
b9a43fd180375525d8d26fa1b489bb2a8c19a6bf
[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.mihome.internal;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.openhab.core.thing.CommonTriggerEvents;
19
20 /**
21  * Maps the various JSON Strings reported from the devices to Channels
22  *
23  * @author Dieter Schmidt - Initial contribution
24  */
25 public class ChannelMapper {
26
27     private static final Map<String, String> SYSTEM_BUTTON_MAP = new HashMap<>();
28     static {
29         // Alphabetical order
30         SYSTEM_BUTTON_MAP.put("CLICK", CommonTriggerEvents.SHORT_PRESSED);
31         SYSTEM_BUTTON_MAP.put("BOTH_CLICK", CommonTriggerEvents.SHORT_PRESSED);
32         SYSTEM_BUTTON_MAP.put("DOUBLE_CLICK", CommonTriggerEvents.DOUBLE_PRESSED);
33         SYSTEM_BUTTON_MAP.put("LONG_CLICK_PRESS", CommonTriggerEvents.LONG_PRESSED);
34         SYSTEM_BUTTON_MAP.put("LONG_CLICK", CommonTriggerEvents.LONG_PRESSED);
35         SYSTEM_BUTTON_MAP.put("LONG_BOTH_CLICK", CommonTriggerEvents.LONG_PRESSED);
36         SYSTEM_BUTTON_MAP.put("LONG_CLICK_RELEASE", "LONG_RELEASED");
37     }
38
39     public static String getChannelEvent(String reportedString) {
40         String ret = SYSTEM_BUTTON_MAP.get(reportedString);
41         if (ret != null) {
42             return ret;
43         } else {
44             return reportedString;
45         }
46     }
47 }