]> git.basschouten.com Git - openhab-addons.git/blob
d667a6df2980cba54ec8b2d4895d0fc67d792e93
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.nuki.internal.converter;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.openhab.binding.nuki.internal.NukiBindingConstants;
19
20 /**
21  * The {@link LockActionConverter} is responsible for mapping Binding Lock States to Bridge HTTP-API Lock Actions.
22  *
23  * @author Markus Katter - Initial contribution
24  */
25 public abstract class LockActionConverter {
26
27     private static Map<Integer, Integer> mapping;
28
29     private static void setupMapping() {
30         mapping = new HashMap<>();
31         mapping.put(NukiBindingConstants.LOCK_STATES_UNLOCKING, NukiBindingConstants.LOCK_ACTIONS_UNLOCK);
32         mapping.put(NukiBindingConstants.LOCK_STATES_LOCKING, NukiBindingConstants.LOCK_ACTIONS_LOCK);
33         mapping.put(NukiBindingConstants.LOCK_STATES_UNLATCHING, NukiBindingConstants.LOCK_ACTIONS_UNLATCH);
34         mapping.put(NukiBindingConstants.LOCK_STATES_UNLOCKING_LOCKNGO,
35                 NukiBindingConstants.LOCK_ACTIONS_LOCKNGO_UNLOCK);
36         mapping.put(NukiBindingConstants.LOCK_STATES_UNLATCHING_LOCKNGO,
37                 NukiBindingConstants.LOCK_ACTIONS_LOCKNGO_UNLATCH);
38     }
39
40     public static int getLockActionFor(int lockState) {
41         if (mapping == null) {
42             setupMapping();
43         }
44         return mapping.get(lockState);
45     }
46
47     public static int getLockStateFor(int lockAction) {
48         if (mapping == null) {
49             setupMapping();
50         }
51         for (Map.Entry<Integer, Integer> entry : mapping.entrySet()) {
52             if (entry.getValue() == lockAction) {
53                 return entry.getKey();
54             }
55         }
56         return 0;
57     }
58 }