2 * Copyright (c) 2010-2022 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;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.library.types.HSBType;
22 * The {@link WlanThermoUtil} class provides conversion functions for the WlanThermo
24 * @author Christian Schlipp - Initial contribution
27 public class WlanThermoUtil {
29 public static String toColorName(String colorHex, Map<String, String> colorMappings, String defaultColorName) {
30 if (!colorHex.startsWith("#")) {
31 colorHex = "#" + colorHex;
34 for (Map.Entry<String, String> entry : colorMappings.entrySet()) {
35 if (entry.getValue().equalsIgnoreCase(colorHex)) {
36 return entry.getKey();
40 return defaultColorName;
43 public static String toHex(HSBType hsb) {
44 return "#" + String.format("%02X", hsb.getRed().intValue()) + String.format("%02X", hsb.getGreen().intValue())
45 + String.format("%02X", hsb.getBlue().intValue());
48 public static <T> T requireNonNull(@Nullable T obj) throws WlanThermoInputException {
50 throw new WlanThermoInputException();