Update weatherforecast.js

Added the option to change the amount of forecasted days returned by the OpenWeatherAPI.
This commit is contained in:
Ashley M. Kirchner
2016-04-29 12:52:10 -06:00
parent e572d544ef
commit 3f040e7744

View File

@@ -14,6 +14,7 @@ Module.register("weatherforecast",{
location: "", location: "",
appid: "", appid: "",
units: config.units, units: config.units,
maxNumberOfDays: 7,
updateInterval: 10 * 60 * 1000, // every 10 minutes updateInterval: 10 * 60 * 1000, // every 10 minutes
animationSpeed: 1000, animationSpeed: 1000,
timeFormat: config.timeFormat, timeFormat: config.timeFormat,
@@ -189,6 +190,12 @@ Module.register("weatherforecast",{
params += "q=" + this.config.location; params += "q=" + this.config.location;
params += "&units=" + this.config.units; params += "&units=" + this.config.units;
params += "&lang=" + this.config.lang; params += "&lang=" + this.config.lang;
/*
* Submit a specific number of days to forecast, between 1 to 16 days.
* The OpenWeatherMap API properly handles values outside of the 1 - 16 range and returns 7 days by default.
* This is simply being pedantic and doing it ourselves.
*/
params += "&cnt=" + (((this.config.maxNumberOfDays < 1) || (this.config.maxNumberOfDays > 16)) ? 7 : this.config.maxNumberOfDays);
params += "&APPID=" + this.config.appid; params += "&APPID=" + this.config.appid;
return params; return params;