2 * Copyright (c) 2010-2023 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.meteoblue.internal;
16 * Model for the meteoblue binding configuration.
18 * @author Chris Carman - Initial contribution
20 public class MeteoBlueConfiguration {
23 public static final int DEFAULT_REFRESH = 240;
26 public static final String SERVICETYPE_COMM = "Commercial";
27 public static final String SERVICETYPE_NONCOMM = "NonCommercial";
28 public static final String COMM_BASE_URL = "http://my.meteoblue.com/dataApi/dispatch.pl?type=json_7day_3h_firstday&";
29 public static final String NONCOMM_BASE_URL = "http://my.meteoblue.com/packages/basic-day?";
30 public static final String URL_MINIMAL_PARAMS = "apikey=#API_KEY#&lat=#LATITUDE#&lon=#LONGITUDE#";
32 // required parameters
33 // servicetype - either Commercial or NonCommercial
34 public String serviceType;
35 // location - lat., long., and alt. in a single string
36 public String location;
38 // optional parameters
39 // refresh - time period in minutes between pulls
40 public Integer refresh;
41 // latitude - the latitude of this location in degrees (-90 to 90)
42 public Double latitude;
43 // longitude - the longitude of this location in degrees (-180 to 180)
44 public Double longitude;
45 // altitude - the height above sea level of the location, in meters
46 public Double altitude;
47 // timeZone - the timezone of the location (see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
48 public String timeZone;
50 // returns the URL for the specified serviceType
51 public static String getURL(String serviceType) {
52 if (SERVICETYPE_COMM.equals(serviceType)) {
53 return COMM_BASE_URL + URL_MINIMAL_PARAMS + "#FORMAT_PARAMS#";
55 return NONCOMM_BASE_URL + URL_MINIMAL_PARAMS + "#FORMAT_PARAMS#";
59 public void parseLocation() {
60 String[] split = location.split(",");
61 String a1 = split.length > 0 ? split[0] : null;
62 String a2 = split.length > 1 ? split[1] : null;
63 String a3 = split.length > 2 ? split[2] : null;
65 if (a1 != null && !a1.isBlank()) {
66 latitude = tryGetDouble(a1);
69 if (a2 != null && !a2.isBlank()) {
70 longitude = tryGetDouble(a2);
73 if (a3 != null && !a3.isBlank()) {
74 altitude = tryGetDouble(a3);
78 private Double tryGetDouble(String toParse) {
80 return Double.parseDouble(toParse);
81 } catch (NumberFormatException e) {