]> git.basschouten.com Git - openhab-addons.git/blob
bd95cff0b6d6b939b8850f5a1f0f46351ac3c7fd
[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.wlanthermo.internal.api.nano;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.wlanthermo.internal.WlanThermoUtil;
20
21 /**
22  * The {@link WlanThermoNanoV1Util} class provides conversion functions for the WlanThermo Nano V1+
23  *
24  * @author Christian Schlipp - Initial contribution
25  */
26 @NonNullByDefault
27 public class WlanThermoNanoV1Util extends WlanThermoUtil {
28
29     private static final Map<String, String> COLOR_MAPPINGS = createColorMap();
30     private static final String DEFAULT_HEX = "#ffffff";
31     private static final String DEFAULT_COLORNAME = "niagara";
32
33     private WlanThermoNanoV1Util() {
34         // hidden
35     }
36
37     private static Map<String, String> createColorMap() {
38         HashMap<String, String> map = new HashMap<>();
39         map.put("niagara", "#5587A2");
40         map.put("rosa", "#FFAEC9");
41         map.put("lapis blue", "#0C4C88");
42         map.put("orange", "#EF562D");
43         map.put("lila", "#A349A4");
44         map.put("red", "#ED1C24");
45         map.put("green", "#22B14C");
46         map.put("gold", "#FFC100");
47         map.put("kale", "#5C7148");
48         map.put("brown", "#804000");
49         return map;
50     }
51
52     /**
53      * Convert WlanThermo Color Name to Hex
54      * 
55      * @param colorName the WlanThermo color name
56      * @return The color as Hex String
57      */
58     public static String toHex(String colorName) {
59         return COLOR_MAPPINGS.getOrDefault(colorName, DEFAULT_HEX);
60     }
61
62     public static String toColorName(String colorHex) {
63         return toColorName(colorHex, COLOR_MAPPINGS, DEFAULT_COLORNAME);
64     }
65 }