]> git.basschouten.com Git - openhab-addons.git/blob
1d4908bdbb0bb847b9e208fe0afa011d67c5df8f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.astro.internal.config;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * Thing configuration from Eclipse SmartHome.
20  *
21  * @author Gerhard Riegler - Initial contribution
22  */
23 @NonNullByDefault
24 public class AstroThingConfig {
25     public @Nullable String geolocation;
26     public @Nullable Double altitude;
27     public @Nullable Double latitude;
28     public @Nullable Double longitude;
29     public boolean useMeteorologicalSeason;
30     public int interval = 300;
31
32     /**
33      * Splits the geolocation into latitude and longitude.
34      */
35     public void parseGeoLocation() {
36         if (geolocation != null) {
37             String[] geoParts = geolocation.split(",");
38             if (geoParts.length == 2) {
39                 latitude = toDouble(geoParts[0]);
40                 longitude = toDouble(geoParts[1]);
41             } else if (geoParts.length == 3) {
42                 latitude = toDouble(geoParts[0]);
43                 longitude = toDouble(geoParts[1]);
44                 altitude = toDouble(geoParts[2]);
45             }
46         }
47     }
48
49     private @Nullable Double toDouble(String value) {
50         try {
51             return Double.parseDouble(value.trim());
52         } catch (NumberFormatException ex) {
53         }
54         return null;
55     }
56 }