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.openhab.binding.lametrictime.api.local.model.Application;
19 import org.openhab.binding.lametrictime.api.local.model.Widget;
20 import org.openhab.binding.lametrictime.api.model.CoreApps;
22 import com.google.gson.JsonPrimitive;
25 * Utility class providing miscellaneous functionality based on the LaMetric Time API to support the binding.
27 * @author Gregory Moyer - Initial contribution
29 public class LaMetricTimeUtil {
30 private static final Map<String, String> CORE_APP_LABELS = new HashMap<>();
32 CORE_APP_LABELS.put(CoreApps.clock().getPackageName(), "Clock");
33 CORE_APP_LABELS.put(CoreApps.countdown().getPackageName(), "Timer");
34 CORE_APP_LABELS.put(CoreApps.radio().getPackageName(), "Radio");
35 CORE_APP_LABELS.put(CoreApps.stopwatch().getPackageName(), "Stopwatch");
36 CORE_APP_LABELS.put(CoreApps.weather().getPackageName(), "Weather");
39 public static String getAppLabel(Application app, Widget widget) {
40 Map<String, JsonPrimitive> settings = widget.getSettings();
41 if (settings != null && settings.containsKey("_title")) {
42 String title = settings.get("_title").getAsString();
43 if (title != null && !title.isEmpty()) {
48 String coreAppLabel = CORE_APP_LABELS.get(app.getPackageName());
49 if (coreAppLabel != null) {
53 return app.getVendor() + "'s App";