Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

[Weather] Allow Forecastio to request units other than SI #5045

Merged
merged 2 commits into from
Jan 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class LocationConfig {
private Integer updateInterval = DEFAULT_UPDATE_INTERVAL;
private String locationId;
private String name;
private String units = "si";

/**
* Returns the language.
Expand Down Expand Up @@ -142,6 +143,20 @@ public void setName(String name) {
this.name = name;
}

/**
* Returns the units of measurement.
*/
public String getMeasurementUnits() {
return units;
}

/**
* Sets the units of measurement.
*/
public void setMeasurementUnits(String u) {
units = u;
}

/**
* Returns true, if this config is valid.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@
* #weather:location.<locationId1>.woeid= (required for Yahoo provider)
* #weather:location.<locationId1>.language=
* #weather:location.<locationId1>.updateInterval= (optional, defaults to 240)
* #weather:location.<locationId1>.units= (optional; defaults to "si")
*
* #weather:location.<locationId2>.latitude= (not required for Yahoo provider)
* #weather:location.<locationId2>.longitude= (not required for Yahoo provider)
* #weather:location.<locationId2>.provider=
* #weather:location.<locationId2>.woeid= (required for Yahoo provider)
* #weather:location.<locationId2>.language=
* #weather:location.<locationId2>.updateInterval= (optional, defaults to 240)
* #weather:location.<locationId2>.units= (optional; defaults to "si")
* </pre>
*
* @author Gerhard Riegler
Expand Down Expand Up @@ -157,6 +159,8 @@ private void parseLocation(String key, String value) throws ConfigurationExcepti
lc.setLanguage(value);
} else if (StringUtils.equalsIgnoreCase(keyId, "name")) {
lc.setName(value);
} else if (StringUtils.equalsIgnoreCase(keyId, "units")) {
lc.setMeasurementUnits(value.toLowerCase());
} else {
logger.debug("Unknown weather configuration setting '{}'. Check openhab.cfg.", key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ private String prepareUrl(String url, LocationConfig locationConfig) {
if (locationConfig.getLongitude() != null) {
url = StringUtils.replace(url, "[LONGITUDE]", locationConfig.getLongitude().toString());
}
if (locationConfig.getMeasurementUnits() != null) {
url = StringUtils.replace(url, "[UNITS]", locationConfig.getMeasurementUnits());
}
url = StringUtils.replace(url, "[LANGUAGE]", locationConfig.getLanguage());
url = StringUtils.replace(url, "[WOEID]", locationConfig.getWoeid());
return url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @since 1.6.0
*/
public class ForecastIoProvider extends AbstractWeatherProvider {
private static final String URL = "https://api.darksky.net/forecast/[API_KEY]/[LATITUDE],[LONGITUDE]?units=si&lang=[LANGUAGE]&exclude=hourly,flags";
private static final String URL = "https://api.darksky.net/forecast/[API_KEY]/[LATITUDE],[LONGITUDE]?units=[UNITS]&lang=[LANGUAGE]&exclude=hourly,flags";

public ForecastIoProvider() {
super(new JsonWeatherParser());
Expand Down
2 changes: 2 additions & 0 deletions distribution/openhabhome/configurations/openhab_default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,7 @@ tcp:refreshinterval=250
#weather:location.<locationId1>.provider=
#weather:location.<locationId1>.language=
#weather:location.<locationId1>.updateInterval=
#weather:location.<locationId1>.units=

#weather:location.<locationId2>.name=
#weather:location.<locationId2>.latitude=
Expand All @@ -2066,6 +2067,7 @@ tcp:refreshinterval=250
#weather:location.<locationId2>.provider=
#weather:location.<locationId2>.language=
#weather:location.<locationId2>.updateInterval=
#weather:location.<locationId2>.units=

################################### Zibase Binding #####################################
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#location.<locationId1>.provider=
#location.<locationId1>.language=
#location.<locationId1>.updateInterval=
#location.<locationId1>.units=

#location.<locationId2>.name=
#location.<locationId2>.latitude= (not required for Yahoo provider)
Expand All @@ -24,3 +25,4 @@
#location.<locationId2>.provider=
#location.<locationId2>.language=
#location.<locationId2>.updateInterval=
#location.<locationId2>.units=