2 * Copyright (c) 2010-2020 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.astro.internal.config;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
19 * Astro Thing configuration.
21 * @author Gerhard Riegler - Initial contribution
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;
33 * Splits the geolocation into latitude and longitude.
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]);
49 private @Nullable Double toDouble(String value) {
51 return Double.parseDouble(value.trim());
52 } catch (NumberFormatException ex) {