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 WeatherUndergroundJsonCurrent} is the Java class used
22 * to map the entry "current_observation" from the JSON response to a Weather
23 * Underground request.
25 * @author Laurent Garnier - Initial contribution
27 public class WeatherUndergroundJsonCurrent {
29 // Commented members indicate properties returned by the API not used by the binding
31 // private Object image;
33 // private Location display_location;
34 private Location observation_location;
35 // private Object estimated;
37 private String station_id;
39 // private String observation_time;
40 // private String observation_time_rfc822;
41 private String observation_epoch;
42 // private String local_time_rfc822;
43 // private String local_epoch;
44 // private String local_tz_short;
45 // private String local_tz_long;
46 // private String local_tz_offset;
48 private String weather;
50 // private String ;temperature_string;
51 private BigDecimal temp_f;
52 private BigDecimal temp_c;
54 private String relative_humidity;
56 // private String wind_string;
57 private String wind_dir;
58 private BigDecimal wind_degrees;
59 private BigDecimal wind_mph;
60 private String wind_gust_mph;
61 private BigDecimal wind_kph;
62 private String wind_gust_kph;
64 private String pressure_mb;
65 private String pressure_in;
66 private String pressure_trend;
68 // private String dewpoint_string;
69 private BigDecimal dewpoint_f;
70 private BigDecimal dewpoint_c;
72 // private String heat_index_string;
73 private String heat_index_f;
74 private String heat_index_c;
76 // private String windchill_string;
77 private String windchill_f;
78 private String windchill_c;
80 // private String feelslike_string;
81 private String feelslike_f;
82 private String feelslike_c;
84 private String visibility_mi;
85 private String visibility_km;
87 private String solarradiation;
90 // private String precip_1hr_string;
91 private String precip_1hr_in;
92 private String precip_1hr_metric;
93 // private String precip_today_string;
94 private String precip_today_in;
95 private String precip_today_metric;
98 private String icon_url;
99 // private String forecast_url;
100 // private String history_url;
101 // private String ob_url;
103 // private String nowcast;
105 public WeatherUndergroundJsonCurrent() {
109 * Get the observation location (full name)
111 * Used to update the channel current#location
113 * @return the observation location or null if not defined
115 public String getLocation() {
116 return (observation_location == null) ? null : observation_location.getFull();
122 * Used to update the channel current#stationId
124 * @return the station ID or null if not defined
126 public String getStationId() {
131 * Get the observation date and time
133 * Used to update the channel current#observationTime
135 * @return the observation date and time or null if not defined
137 public ZonedDateTime getObservationTime(ZoneId zoneId) {
138 return WeatherUndergroundJsonUtils.convertToZonedDateTime(observation_epoch, zoneId);
142 * Get the current weather conditions
144 * Used to update the channel current#conditions
146 * @return the current weather conditions or null if not defined
148 public String getConditions() {
153 * Get the current temperature in degrees Celsius
155 * Used to update the channel current#temperature
157 * @return the current temperature in degrees Celsius or null if not defined
159 public BigDecimal getTemperatureC() {
164 * Get the current temperature in degrees Fahrenheit
166 * Used to update the channel current#temperature
168 * @return the current temperature in degrees Fahrenheit or null if not defined
170 public BigDecimal getTemperatureF() {
175 * Get the current relative humidity
177 * Used to update the channel current#relativeHumidity
179 * @return the current relative humidity or null if not defined
181 public Integer getRelativeHumidity() {
182 if (relative_humidity != null && !relative_humidity.isEmpty() && !relative_humidity.equalsIgnoreCase("N/A")) {
183 return WeatherUndergroundJsonUtils.convertToInteger(relative_humidity.replace("%", ""));
189 * Get the wind direction as a text
191 * Used to update the channel current#windDirection
193 * @return the wind direction or null if not defined
195 public String getWindDirection() {
200 * Get the wind direction in degrees
202 * Used to update the channel current#windDirectionDegrees
204 * @return the wind direction in degrees or null if not defined
206 public BigDecimal getWindDirectionDegrees() {
211 * Get the wind speed in km/h
213 * Used to update the channel current#windSpeed
215 * @return the wind speed in km/h or null if not defined
217 public BigDecimal getWindSpeedKmh() {
222 * Get the wind speed in mph
224 * Used to update the channel current#windSpeed
226 * @return the wind speed in mph or null if not defined
228 public BigDecimal getWindSpeedMph() {
233 * Get the wind gust in km/h
235 * Used to update the channel current#windGust
237 * @return the wind gust in km/h or null if not defined
239 public BigDecimal getWindGustKmh() {
240 return WeatherUndergroundJsonUtils.convertToBigDecimal(wind_gust_kph);
244 * Get the wind gust in mph
246 * Used to update the channel current#windGust
248 * @return the wind gust in mph or null if not defined
250 public BigDecimal getWindGustMph() {
251 return WeatherUndergroundJsonUtils.convertToBigDecimal(wind_gust_mph);
255 * Get the pressure in hPa
257 * Used to update the channel current#pressure
259 * @return the pressure in hPa or null if not defined
261 public BigDecimal getPressureHPa() {
262 return WeatherUndergroundJsonUtils.convertToBigDecimal(pressure_mb);
266 * Get the pressure in inHg
268 * Used to update the channel current#pressure
270 * @return the pressure in inHg or null if not defined
272 public BigDecimal getPressureInHg() {
273 return WeatherUndergroundJsonUtils.convertToBigDecimal(pressure_in);
277 * Get the pressure trend
279 * Used to update the channel current#pressureTrend
281 * @return the pressure trend or null if not defined
283 public String getPressureTrend() {
284 return WeatherUndergroundJsonUtils.convertToTrend(pressure_trend);
288 * Get the dew point temperature in degrees Celsius
290 * Used to update the channel current#dewPoint
292 * @return the dew point temperature in degrees Celsius or null if not defined
294 public BigDecimal getDewPointC() {
299 * Get the dew point temperature in degrees Fahrenheit
301 * Used to update the channel current#dewPoint
303 * @return the dew point temperature in degrees Fahrenheit or null if not defined
305 public BigDecimal getDewPointF() {
310 * Get the heat index in degrees Celsius
312 * Used to update the channel current#heatIndex
314 * @return the heat index in degrees Celsius or null if not defined
316 public BigDecimal getHeatIndexC() {
317 return WeatherUndergroundJsonUtils.convertToBigDecimal(heat_index_c);
321 * Get the heat index in degrees Fahrenheit
323 * Used to update the channel current#heatIndex
325 * @return the heat index in degrees Fahrenheit or null if not defined
327 public BigDecimal getHeatIndexF() {
328 return WeatherUndergroundJsonUtils.convertToBigDecimal(heat_index_f);
332 * Get the wind chill temperature in degrees Celsius
334 * Used to update the channel current#windChill
336 * @return the wind chill temperature in degrees Celsius or null if not defined
338 public BigDecimal getWindChillC() {
339 return WeatherUndergroundJsonUtils.convertToBigDecimal(windchill_c);
343 * Get the wind chill temperature in degrees Fahrenheit
345 * Used to update the channel current#windChill
347 * @return the wind chill temperature in degrees Fahrenheit or null if not defined
349 public BigDecimal getWindChillF() {
350 return WeatherUndergroundJsonUtils.convertToBigDecimal(windchill_f);
354 * Get the feeling temperature in degrees Celsius
356 * Used to update the channel current#feelingTemperature
358 * @return the feeling temperature in degrees Celsius or null if not defined
360 public BigDecimal getFeelingTemperatureC() {
361 return WeatherUndergroundJsonUtils.convertToBigDecimal(feelslike_c);
365 * Get the feeling temperature in degrees Fahrenheit
367 * Used to update the channel current#feelingTemperature
369 * @return the feeling temperature in degrees Fahrenheit or null if not defined
371 public BigDecimal getFeelingTemperatureF() {
372 return WeatherUndergroundJsonUtils.convertToBigDecimal(feelslike_f);
376 * Get the visibility in kilometers
378 * Used to update the channel current#visibility
380 * @return the visibility in kilometers or null if not defined
382 public BigDecimal getVisibilityKm() {
383 return WeatherUndergroundJsonUtils.convertToBigDecimal(visibility_km);
387 * Get the visibility in miles
389 * Used to update the channel current#visibility
391 * @return the visibility in miles or null if not defined
393 public BigDecimal getVisibilityMi() {
394 return WeatherUndergroundJsonUtils.convertToBigDecimal(visibility_mi);
398 * Get the precipitation in the last hour in millimeters
400 * Used to update the channel current#precipitationHour
402 * @return the precipitation in the last hour in millimeters or null if not defined
404 public BigDecimal getPrecipitationHourMm() {
405 BigDecimal result = WeatherUndergroundJsonUtils.convertToBigDecimal(precip_1hr_metric);
406 if ((result != null) && (result.doubleValue() < 0.0)) {
407 result = BigDecimal.ZERO;
413 * Get the precipitation in the last hour in inches
415 * Used to update the channel current#precipitationHour
417 * @return the precipitation in the last hour in inches or null if not defined
419 public BigDecimal getPrecipitationHourIn() {
420 BigDecimal result = WeatherUndergroundJsonUtils.convertToBigDecimal(precip_1hr_in);
421 if ((result != null) && (result.doubleValue() < 0.0)) {
422 result = BigDecimal.ZERO;
428 * Get the precipitation for the full day in millimeters
430 * Used to update the channel current#precipitationDay
432 * @return the precipitation for the full day in millimeters or null if not defined
434 public BigDecimal getPrecipitationDayMm() {
435 return WeatherUndergroundJsonUtils.convertToBigDecimal(precip_today_metric);
439 * Get the precipitation for the full day in inches
441 * Used to update the channel current#precipitationDay
443 * @return the precipitation for the full day in inches or null if not defined
445 public BigDecimal getPrecipitationDayIn() {
446 return WeatherUndergroundJsonUtils.convertToBigDecimal(precip_today_in);
450 * Get the solar radiation in Watts/sq. m
452 * Used to update the channel current#solarRadiation
454 * @return the solar radiation or null if not defined or negative
456 public BigDecimal getSolarRadiation() {
457 BigDecimal value = WeatherUndergroundJsonUtils.convertToBigDecimal(solarradiation);
458 // We check that the index is not negative
459 if (value != null && value.signum() == -1) {
468 * Used to update the channel current#UVIndex
470 * @return the UV Index or null if not defined or negative
472 public BigDecimal getUVIndex() {
473 BigDecimal value = WeatherUndergroundJsonUtils.convertToBigDecimal(UV);
474 // We check that the index is not negative
475 if (value != null && value.signum() == -1) {
482 * Get the icon URL representing the current weather conditions
484 * Used to update the channel current#icon
486 * @return the icon URL representing the current weather conditions or null if not defined
488 public URL getIcon() {
489 return WeatherUndergroundJsonUtils.getValidUrl(icon_url);
493 * Get the icon key used in the URL representing the current weather conditions
495 * Used to update the channel current#iconKey
497 * @return the icon key used in the URL representing the current weather conditions
499 public String getIconKey() {
506 private String state;
507 private String state_name;
508 private String country;
509 private String country_iso3166;
511 private String magic;
513 private String latitude;
514 private String longitude;
515 private String elevation;
520 public String getFull() {
524 public String getCity() {
528 public String getState() {
532 public String getStateName() {
536 public String getCountry() {
540 public String getCountryIso3166() {
541 return country_iso3166;
544 public String getZip() {
548 public String getMagic() {
552 public String getWmo() {
556 public String getLatitude() {
560 public String getLongitude() {
564 public String getElevation() {