2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nuki.internal.converter;
15 import java.util.HashMap;
18 import org.openhab.binding.nuki.internal.NukiBindingConstants;
21 * The {@link LockActionConverter} is responsible for mapping Binding Lock States to Bridge HTTP-API Lock Actions.
23 * @author Markus Katter - Initial contribution
25 public abstract class LockActionConverter {
27 private static Map<Integer, Integer> mapping;
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);
40 public static int getLockActionFor(int lockState) {
41 if (mapping == null) {
44 return mapping.get(lockState);
47 public static int getLockStateFor(int lockAction) {
48 if (mapping == null) {
51 for (Map.Entry<Integer, Integer> entry : mapping.entrySet()) {
52 if (entry.getValue() == lockAction) {
53 return entry.getKey();