2 * Copyright (c) 2010-2020 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.wlanthermo.internal.api.nano;
15 import java.util.HashMap;
19 * The {@link UtilNano} class provides conversion functions for the WlanThermo Nano
21 * @author Christian Schlipp - Initial contribution
23 public class UtilNano {
25 private static final Map<String, String> COLOR_MAPPINGS = createColorMap();
26 private static final String DEFAULT_HEX = "#ffffff";
27 private static final String DEFAULT_COLORNAME = "niagara";
33 private static Map<String, String> createColorMap() {
34 HashMap<String, String> map = new HashMap<>();
35 map.put("niagara", "#5587A2");
36 map.put("rosa", "#FFAEC9");
37 map.put("lapis blue", "#0C4C88");
38 map.put("orange", "#EF562D");
39 map.put("lila", "#A349A4");
40 map.put("red", "#ED1C24");
41 map.put("green", "#22B14C");
42 map.put("gold", "#FFC100");
43 map.put("kale", "#5C7148");
44 map.put("brown", "#804000");
49 * Convert WlanThermo Color Name to Hex
51 * @param colorName the WlanThermo color name
52 * @return The color as Hex String
54 public static String toHex(String colorName) {
55 return COLOR_MAPPINGS.getOrDefault(colorName, DEFAULT_HEX);
58 public static String toColorName(String colorHex) {
59 String colorName = null;
60 if (!colorHex.startsWith("#")) {
61 colorHex = "#" + colorHex;
63 for (Map.Entry<String, String> entry : COLOR_MAPPINGS.entrySet()) {
64 if (entry.getValue().equalsIgnoreCase(colorHex)) {
65 colorName = entry.getKey();
68 if (colorName == null) {
69 colorName = DEFAULT_COLORNAME;