]> git.basschouten.com Git - openhab-addons.git/blob
908680085298091c1cbb65ef7767af097039a6f1
[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.gpstracker.internal.config;
14
15 import java.math.BigDecimal;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.config.core.Configuration;
20 import org.openhab.core.library.types.PointType;
21
22 /**
23  * The {@link ConfigHelper} class is a configuration helper for channels and profiles.
24  *
25  * @author Gabor Bicskei - Initial contribution
26  */
27 @NonNullByDefault
28 public class ConfigHelper {
29     // configuration constants
30     public static final String CONFIG_TRACKER_ID = "trackerId";
31     public static final String CONFIG_REGION_NAME = "regionName";
32     public static final String CONFIG_REGION_RADIUS = "regionRadius";
33     public static final String CONFIG_REGION_CENTER_LOCATION = "regionCenterLocation";
34     public static final String CONFIG_ACCURACY_THRESHOLD = "accuracyThreshold";
35
36     /**
37      * Constructor.
38      */
39     private ConfigHelper() {
40     }
41
42     public static double getRegionRadius(Configuration config) {
43         return ((BigDecimal) config.get(CONFIG_REGION_RADIUS)).doubleValue();
44     }
45
46     public static double getAccuracyThreshold(Configuration config) {
47         Object value = config.get(CONFIG_ACCURACY_THRESHOLD);
48         return value != null ? ((BigDecimal) value).doubleValue() : 0;
49     }
50
51     public static String getRegionName(Configuration config) {
52         return (String) config.get(CONFIG_REGION_NAME);
53     }
54
55     public static String getTrackerId(Configuration config) {
56         return (String) config.get(CONFIG_TRACKER_ID);
57     }
58
59     public static @Nullable PointType getRegionCenterLocation(Configuration config) {
60         String location = (String) config.get(CONFIG_REGION_CENTER_LOCATION);
61         return location != null ? new PointType(location) : null;
62     }
63 }