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