Add a small forecast example.

This commit is contained in:
Michael Teeuw
2017-09-22 13:26:44 +02:00
parent 713111254b
commit ff9c6bac0a
4 changed files with 101 additions and 14 deletions

View File

@@ -42,6 +42,28 @@ WeatherProvider.register("openweathermap", {
})
},
// Overwrite the fetchCurrentWeather method.
fetchWeatherForecast: function() {
// I haven't yet implemented the real api call, so let's just generate some random data.
var forecast = []
var today = moment()
for (var i = 0; i < 5; i++ ) {
var weatherObject = new WeatherObject()
weatherObject.date = moment(today).add(i, "days")
weatherObject.minTemperature = Math.random() * 10 + 10
weatherObject.maxTemperature = Math.random() * 15 + 10
forecast.push(weatherObject)
}
this.setWeatherForecast(forecast)
},
/** OpenWeatherMap Specific Methods - These are not part of the default provider methods */
@@ -52,6 +74,8 @@ WeatherProvider.register("openweathermap", {
generateWeatherObjectFromCurrentWeather: function(currentWeatherData) {
var currentWeather = new WeatherObject()
currentWeather.date = new Date
currentWeather.humidity = currentWeatherData.main.humidity ? parseFloat(currentWeatherData.main.humidity) : null
currentWeather.temperature = currentWeatherData.main.temp ? parseFloat(currentWeatherData.main.temp) : null
currentWeather.windSpeed = currentWeatherData.wind.speed ? parseFloat(currentWeatherData.wind.speed) : null