2 * Copyright (c) 2010-2023 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.lametrictime.internal;
15 import java.util.HashMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.lametrictime.internal.api.dto.CoreApps;
20 import org.openhab.binding.lametrictime.internal.api.local.dto.Application;
21 import org.openhab.binding.lametrictime.internal.api.local.dto.Widget;
23 import com.google.gson.JsonPrimitive;
26 * Utility class providing miscellaneous functionality based on the LaMetric Time API to support the binding.
28 * @author Gregory Moyer - Initial contribution
31 public class LaMetricTimeUtil {
32 private static final Map<String, String> CORE_APP_LABELS = new HashMap<>();
34 CORE_APP_LABELS.put(CoreApps.clock().getPackageName(), "Clock");
35 CORE_APP_LABELS.put(CoreApps.countdown().getPackageName(), "Timer");
36 CORE_APP_LABELS.put(CoreApps.radio().getPackageName(), "Radio");
37 CORE_APP_LABELS.put(CoreApps.stopwatch().getPackageName(), "Stopwatch");
38 CORE_APP_LABELS.put(CoreApps.weather().getPackageName(), "Weather");
41 public static String getAppLabel(Application app, Widget widget) {
42 Map<String, JsonPrimitive> settings = widget.getSettings();
43 if (settings != null && settings.containsKey("_title")) {
44 String title = settings.get("_title").getAsString();
45 if (title != null && !title.isEmpty()) {
50 String coreAppLabel = CORE_APP_LABELS.get(app.getPackageName());
51 if (coreAppLabel != null) {
55 return app.getVendor() + "'s App";