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.weatherunderground.internal.json;
15 import java.math.BigDecimal;
17 import java.time.ZoneId;
18 import java.time.ZonedDateTime;
21 * The {@link WeatherUndergroundJsonForecastDay} is the Java class used
22 * to map the list element of the entry "forecast.simpleforecast.forecastday"
23 * from the JSON response to a Weather Underground request.
25 * @author Laurent Garnier - Initial contribution
27 public class WeatherUndergroundJsonForecastDay {
29 // Commented members indicate properties returned by the API not used by the binding
31 private ForecastDate date;
32 private Integer period;
34 private ForecastTemperature high;
35 private ForecastTemperature low;
37 private String conditions;
40 private String icon_url;
41 // private String skyicon;
45 private ForecastPrecipitation qpf_allday;
46 // private ForecastPrecipitation qpf_day;
47 // private ForecastPrecipitation qpf_night;
48 private ForecastPrecipitation snow_allday;
49 // private ForecastPrecipitation snow_day;
50 // private ForecastPrecipitation snow_night;
52 private ForecastWind maxwind;
53 private ForecastWind avewind;
55 private Integer avehumidity;
56 // private Integer minhumidity;
57 // private Integer maxhumidity;
59 public WeatherUndergroundJsonForecastDay() {
63 * Get the forecast date and time
65 * Used to update the channel forecastDayX#forecastTime
67 * @return the forecast date and time or null if not defined
69 public ZonedDateTime getForecastTime(ZoneId zoneId) {
70 return WeatherUndergroundJsonUtils.convertToZonedDateTime((date == null) ? null : date.getEpoch(), zoneId);
74 * Get the period number
76 * @return the period number
78 public Integer getPeriod() {
83 * Get the weather forecast conditions
85 * Used to update the channel forecastDayX#conditions
87 * @return the weather forecast conditions or null if not defined
89 public String getConditions() {
94 * Get the icon URL representing the weather forecast conditions
96 * Used to update the channel forecastDayX#icon
98 * @return the icon URL representing the weather forecast conditions or null if not defined
100 public URL getIcon() {
101 return WeatherUndergroundJsonUtils.getValidUrl(icon_url);
105 * Get the icon key used in the URL representing the weather forecast conditions
107 * Used to update the channel forecastDayX#iconKey
109 * @return the icon key used in the URL representing the weather forecast conditions
111 public String getIconKey() {
116 * Get the minimum temperature in degrees Celsius
118 * Used to update the channel forecastDayX#minTemperature
120 * @return the minimum temperature in degrees Celsius or null if not defined
122 public BigDecimal getMinTemperatureC() {
123 return (low == null) ? null : WeatherUndergroundJsonUtils.convertToBigDecimal(low.getCelsius());
127 * Get the minimum temperature in degrees Fahrenheit
129 * Used to update the channel forecastDayX#minTemperature
131 * @return the minimum temperature in degrees Fahrenheit or null if not defined
133 public BigDecimal getMinTemperatureF() {
134 return (low == null) ? null : WeatherUndergroundJsonUtils.convertToBigDecimal(low.getFahrenheit());
138 * Get the maximum temperature in degrees Celsius
140 * Used to update the channel forecastDayX#maxTemperature
142 * @return the maximum temperature in degrees Celsius or null if not defined
144 public BigDecimal getMaxTemperatureC() {
145 return (high == null) ? null : WeatherUndergroundJsonUtils.convertToBigDecimal(high.getCelsius());
149 * Get the maximum temperature in degrees Fahrenheit
151 * Used to update the channel forecastDayX#maxTemperature
153 * @return the maximum temperature in degrees Fahrenheit or null if not defined
155 public BigDecimal getMaxTemperatureF() {
156 return (high == null) ? null : WeatherUndergroundJsonUtils.convertToBigDecimal(high.getFahrenheit());
160 * Get the relative humidity
162 * Used to update the channel forecastDayX#relativeHumidity
164 * @return the relative humidity or null if not defined
166 public Integer getRelativeHumidity() {
171 * Get the probability of precipitation
173 * Used to update the channel forecastDayX#probaPrecipitation
175 * @return the probability of precipitation or null if not defined
177 public Integer getProbaPrecipitation() {
182 * Get the precipitation for the full day in millimeters
184 * Used to update the channel forecastDayX#precipitationDay
186 * @return the precipitation for the full day in millimeters or null if not defined
188 public BigDecimal getPrecipitationDayMm() {
189 return (qpf_allday == null) ? null : qpf_allday.mm;
193 * Get the precipitation for the full day in inches
195 * Used to update the channel forecastDayX#precipitation
197 * @return the precipitation for the full day in inches or null if not defined
199 public BigDecimal getPrecipitationDayIn() {
200 return (qpf_allday == null) ? null : qpf_allday.in;
204 * Get the amount of snow for the full day in centimeters
206 * Used to update the channel forecastDayX#snow
208 * @return the amount of snow for the full day in centimeters or null if not defined
210 public BigDecimal getSnowCm() {
211 return (snow_allday == null) ? null : snow_allday.cm;
215 * Get the amount of snow for the full day in inches
217 * Used to update the channel forecastDayX#snow
219 * @return the amount of snow for the full day in inches or null if not defined
221 public BigDecimal getSnowIn() {
222 return (snow_allday == null) ? null : snow_allday.in;
226 * Get the maximum wind direction as a text
228 * Used to update the channel forecastDayX#maxWindDirection
230 * @return the maximum wind direction or null if not defined
232 public String getMaxWindDirection() {
233 return (maxwind == null) ? null : maxwind.getDir();
237 * Get the maximum wind direction in degrees
239 * Used to update the channel forecastDayX#maxWindDirectionDegrees
241 * @return the maximum wind direction in degrees or null if not defined
243 public BigDecimal getMaxWindDirectionDegrees() {
244 return (maxwind == null) ? null : WeatherUndergroundJsonUtils.convertToBigDecimal(maxwind.getDegrees());
248 * Get the maximum wind speed in km/h
250 * Used to update the channel forecastDayX#maxWindSpeed
252 * @return the maximum wind speed in km/h or null if not defined
254 public BigDecimal getMaxWindSpeedKmh() {
255 return (maxwind == null) ? null : maxwind.getKph();
259 * Get the maximum wind speed in mph
261 * Used to update the channel forecastDayX#maxWindSpeed
263 * @return the maximum wind speed in mph or null if not defined
265 public BigDecimal getMaxWindSpeedMph() {
266 return (maxwind == null) ? null : maxwind.getMph();
270 * Get the average wind direction as a text
272 * Used to update the channel forecastDayX#averageWindDirection
274 * @return the average wind direction or null if not defined
276 public String getAverageWindDirection() {
277 return (avewind == null) ? null : avewind.getDir();
281 * Get the average wind direction in degrees
283 * Used to update the channel forecastDayX#averageWindDirectionDegrees
285 * @return the average wind direction in degrees or null if not defined
287 public BigDecimal getAverageWindDirectionDegrees() {
288 return (avewind == null) ? null : WeatherUndergroundJsonUtils.convertToBigDecimal(avewind.getDegrees());
292 * Get the average wind speed in km/h
294 * Used to update the channel forecastDayX#averageWindSpeed
296 * @return the average wind speed in km/h or null if not defined
298 public BigDecimal getAverageWindSpeedKmh() {
299 return (avewind == null) ? null : avewind.getKph();
303 * Get the average wind speed in mph
305 * Used to update the channel forecastDayX#averageWindSpeed
307 * @return the average wind speed in mph or null if not defined
309 public BigDecimal getAverageWindSpeedMph() {
310 return (avewind == null) ? null : avewind.getMph();
315 // Commented members indicate properties returned by the API not used by the binding
317 private String epoch;
318 // private String pretty;
319 // private Integer day;
320 // private Integer month;
321 // private Integer year;
322 // private Integer yday;
323 // private Integer hour;
324 // private String min;
325 // private Integer sec;
326 // private String isdst;
327 // private String monthname;
328 // private String monthname_short;
329 // private String weekday_short;
330 // private String weekday;
331 // private String ampm;
332 // private String tz_short;
333 // private String tz_long;
338 public String getEpoch() {
343 class ForecastTemperature {
344 private String fahrenheit;
345 private String celsius;
347 ForecastTemperature() {
350 public String getFahrenheit() {
354 public String getCelsius() {
359 class ForecastPrecipitation {
360 private BigDecimal in;
361 private BigDecimal mm;
362 private BigDecimal cm;
364 ForecastPrecipitation() {
367 public BigDecimal getIn() {
371 public BigDecimal getMm() {
375 public BigDecimal getCm() {
381 private BigDecimal mph;
382 private BigDecimal kph;
384 private String degrees;
389 public BigDecimal getMph() {
393 public BigDecimal getKph() {
397 public String getDir() {
401 public String getDegrees() {