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