Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weather refactoring #1488

Merged
merged 35 commits into from
Dec 28, 2018
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ef17259
A first setup of the new Weather Module
MichMich Sep 21, 2017
7f2e643
Add Dark Sky Module
nhubbard Sep 22, 2017
2bf18d8
Fix Indentation?
nhubbard Sep 22, 2017
5b1462a
Add readme.
MichMich Sep 22, 2017
7131112
First implementation of the currentWeatherView
MichMich Sep 22, 2017
ff9c6ba
Add a small forecast example.
MichMich Sep 22, 2017
7be6031
Merge branch 'weather-refactor' of https://github.com/MichMich/MagicM…
nhubbard Sep 29, 2017
837e275
Update fork
nhubbard Sep 29, 2017
cd129fb
Revert "Fix Indentation?"
nhubbard Sep 30, 2017
3fa810b
Merge branch 'develop' into weather-refactor
MichMich Oct 1, 2017
99e3a47
Use templates to render weather.
MichMich Oct 1, 2017
ad240cf
Fix lint errors.
MichMich Oct 1, 2017
681a845
Add Darksky provider.
MichMich Oct 3, 2017
0776dfc
Minor changes.
MichMich Oct 18, 2017
d567fd4
Merge branch 'develop' into weather-refactor
MichMich Oct 18, 2017
ec2169e
Merge branch 'develop' into weather-refactor
MichMich Oct 18, 2017
241ff5c
Set temperature rounding.
MichMich Oct 18, 2017
ab732b5
Make all visiable values dynamic.
MichMich Oct 18, 2017
995296e
Merge branch 'develop' into weather-refactor
MichMich Oct 18, 2017
a79e1b6
Rename templates to .njk files to allow syntax highlighting.
MichMich Oct 18, 2017
22a50b7
Show unit.
MichMich Oct 19, 2017
16c8878
Show humidity.
MichMich Oct 19, 2017
07d35a8
Remove todo item.
MichMich Oct 19, 2017
91ddc00
fix moment, add unit filter
fewieden May 21, 2018
3341c9e
start with forecast template
fewieden May 21, 2018
66ceafd
show indoor data, add loading message
fewieden Jun 16, 2018
0fe79b5
indoor data, new filter, small cleanup
fewieden Jul 2, 2018
6383618
weatherprovider
fewieden Dec 27, 2018
ebee80d
small improvements
fewieden Dec 27, 2018
95adc0a
forecast
fewieden Dec 27, 2018
0ed2ba0
darksky forecast and darksky current weather fixes
fewieden Dec 27, 2018
1920f81
config options and documentation
fewieden Dec 27, 2018
10bc326
cleanup
fewieden Dec 27, 2018
7a0bc81
Merge branch 'develop' of https://github.com/MichMich/MagicMirror int…
fewieden Dec 27, 2018
b853c00
Add changelog entry
fewieden Dec 27, 2018
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
Prev Previous commit
Next Next commit
forecast
  • Loading branch information
fewieden committed Dec 27, 2018
commit 95adc0aec1b74167d79478be8627da7b75111e66
33 changes: 18 additions & 15 deletions modules/default/weather/forecast.njk
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
{% if forecast %}
<div class="normal medium">
<table class="small">
{% for f in forecast %}
<tr class="{% if config.colored %}colored{% endif %}">
<td class="day">{{f.day}}</td>
<td class="bright weather-icon"><span class="wi weathericon {{f.icon}}"></span></td>
<td class="align-right bright max-temp">
{{f.maxTemperature | roundValue | unit("temperature")}}
<table class="{{config.tableClass}}">
{% for f in forecast %}
<tr {% if config.colored %}class="colored"{% endif %}>
<td class="day">{{f.date.format('ddd')}}</td>
<td class="bright weather-icon"><span class="wi weathericon wi-{{f.weatherType}}"></span></td>
<td class="align-right bright max-temp">
{{f.maxTemperature | roundValue | unit("temperature")}}
</td>
<td class="align-right min-temp">
{{f.minTemperature | roundValue | unit("temperature")}}
</td>
{% if config.showRainAmount %}
<td class="align-right bright rain">
{{f.rain | formatRain}}
</td>
<td class="align-right min-temp">
{{f.minTemperature | roundValue | unit("temperature")}}
</td>
</tr>
{% endfor %}
</table>
</div>
{% endif %}
</tr>
{% endfor %}
</table>
{% else %}
{{"LOADING" | translate}}
{% endif %}
87 changes: 52 additions & 35 deletions modules/default/weather/providers/openweathermap.js
Original file line number Diff line number Diff line change
@@ -12,28 +12,22 @@
WeatherProvider.register("openweathermap", {

// Set the name of the provider.
// This isn't strictly nessecery, since it will fallback to the provider identifier
// This isn't strictly necessary, since it will fallback to the provider identifier
// But for debugging (and future alerts) it would be nice to have the real name.
providerName: "OpenWeatherMap",

// Overwrite the fetchCurrentWeather method.
fetchCurrentWeather: function() {
var apiVersion = "2.5"
var apiBase = "http://api.openweathermap.org/data/"
var weatherEndpoint = "weather"

var url = apiBase + apiVersion + "/" + weatherEndpoint + this.getParams()

this.fetchData(url)
this.fetchData(this.getUrl())
.then(data => {
Log.log(data)

if (!data || !data.main || typeof data.main.temp === "undefined") {
// Did not receive usable new data.
// Maybe this needs a better check?
return;
}

this.setFetchedLocation(data.name + ', ' + data.sys.country)

var currentWeather = this.generateWeatherObjectFromCurrentWeather(data)
this.setCurrentWeather(currentWeather)
})
@@ -44,49 +38,72 @@ WeatherProvider.register("openweathermap", {

// Overwrite the fetchCurrentWeather method.
fetchWeatherForecast: function() {
this.fetchData(this.getUrl())
.then(data => {
if (!data || !data.list || !data.list.length) {
// Did not receive usable new data.
// Maybe this needs a better check?
return;
}

// 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.setFetchedLocation(data.city.name + ', ' + data.city.country)

this.setWeatherForecast(forecast)
var forecast = this.generateWeatherObjectsFromForecast(data.list)
this.setWeatherForecast(forecast)
})
.catch(function(request) {
Log.error("Could not load data ... ", request)
})
},



/** OpenWeatherMap Specific Methods - These are not part of the default provider methods */

/*
* Gets the complete url for the request
*/
getUrl: function() {
return this.config.apiBase + this.config.apiVersion + this.config.weatherEndpoint + this.getParams()
},

/*
* Generate a WeatherObject based on currentWeatherInformation
*/
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
currentWeather.windDirection = currentWeatherData.wind.deg ? currentWeatherData.wind.deg : null
currentWeather.weatherType = currentWeatherData.weather[0].icon ? this.convertWeatherType(currentWeatherData.weather[0].icon) : null
currentWeather.sunrise = currentWeatherData.sys.sunrise ? new Date(currentWeatherData.sys.sunrise * 1000) : null
currentWeather.sunset = currentWeatherData.sys.sunset ? new Date(currentWeatherData.sys.sunset * 1000) : null
currentWeather.humidity = currentWeatherData.main.humidity
currentWeather.temperature = currentWeatherData.main.temp
currentWeather.windSpeed = currentWeatherData.wind.speed
currentWeather.windDirection = currentWeatherData.wind.deg
currentWeather.weatherType = this.convertWeatherType(currentWeatherData.weather[0].icon)
currentWeather.sunrise = moment(currentWeatherData.sys.sunrise, "X")
currentWeather.sunset = moment(currentWeatherData.sys.sunset, "X")

return currentWeather
},

/*
* Generate WeatherObjects based on forecast information
*/
generateWeatherObjectsFromForecast: function(forecasts) {
var days = []

for (var forecast of forecasts) {
var weather = new WeatherObject()

weather.date = moment(forecast.dt, "X")
weather.minTemperature = forecast.temp.min
weather.maxTemperature = forecast.temp.max
weather.weatherType = this.convertWeatherType(forecast.weather[0].icon)
weather.rain = forecast.rain

days.push(weather)
}

return days
},

/*
* Convert the OpenWeatherMap icons to a more usable name.
*/