]> git.basschouten.com Git - openhab-addons.git/blob
4093d42122bbce393048e4107bb9af4a2a40888f
[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.esp32;
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 WlanThermoEsp32Util} class provides conversion functions for the WlanThermo Nano V3
23  *
24  * @author Christian Schlipp - Initial contribution
25  */
26 @NonNullByDefault
27 public class WlanThermoEsp32Util 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 = "undefined";
32
33     private WlanThermoEsp32Util() {
34         // hidden
35     }
36
37     private static Map<String, String> createColorMap() {
38         HashMap<String, String> map = new HashMap<>();
39         map.put("yellow", "#FFFF00");
40         map.put("dark yellow", "#FFC002");
41         map.put("green", "#00FF00");
42         map.put("white", "#FFFFFF");
43         map.put("pink", "#FF1DC4");
44         map.put("orange", "#E46C0A");
45         map.put("olive", "#C3D69B");
46         map.put("light blue", "#0FE6F1");
47         map.put("blue", "#0000FF");
48         map.put("dark green", "#03A923");
49         map.put("brown", "#C84B32");
50         map.put("light brown", "#FF9B69");
51         map.put("dark blue", "#5082BE");
52         map.put("light pink", "#FFB1D0");
53         map.put("light green", "#A6EF03");
54         map.put("dark pink", "#D42A6B");
55         map.put("beige", "#FFDA8F");
56         map.put("azure", "#00B0F0");
57         map.put("dark olive", "#948A54");
58         return map;
59     }
60
61     /**
62      * Convert WlanThermo Color Name to Hex
63      *
64      * @param colorName the WlanThermo color name
65      * @return The color as Hex String
66      */
67     public static String toHex(String colorName) {
68         return COLOR_MAPPINGS.getOrDefault(colorName, DEFAULT_HEX);
69     }
70
71     public static String toColorName(String colorHex) {
72         return toColorName(colorHex, COLOR_MAPPINGS, DEFAULT_COLORNAME);
73     }
74 }