mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
Issue #2221 - Weather forecast always shows night icons in day time
This commit is contained in:
parent
3eda8af671
commit
2c3e8533c7
@ -28,6 +28,7 @@ _This release is scheduled to be released on 2021-04-01._
|
|||||||
|
|
||||||
- Added default log levels to stop calendar log spamming.
|
- Added default log levels to stop calendar log spamming.
|
||||||
- Fix socket.io cors errors, see [breaking change since socket.io v3](https://socket.io/docs/v3/handling-cors/)
|
- Fix socket.io cors errors, see [breaking change since socket.io v3](https://socket.io/docs/v3/handling-cors/)
|
||||||
|
- Fix Issue with weather forecast icons due to fixed day start and end time (#2221)
|
||||||
|
|
||||||
## [2.14.0] - 2021-01-01
|
## [2.14.0] - 2021-01-01
|
||||||
|
|
||||||
|
@ -351,6 +351,13 @@ Module.register("weatherforecast", {
|
|||||||
this.forecast = [];
|
this.forecast = [];
|
||||||
var lastDay = null;
|
var lastDay = null;
|
||||||
var forecastData = {};
|
var forecastData = {};
|
||||||
|
var dayStarts = 8;
|
||||||
|
var dayEnds = 17;
|
||||||
|
|
||||||
|
if (data.city && data.city.sunrise && data.city.sunset) {
|
||||||
|
dayStarts = moment.unix(data.city.sunrise).toDate().getHours();
|
||||||
|
dayEnds = moment.unix(data.city.sunset).toDate().getHours();
|
||||||
|
}
|
||||||
|
|
||||||
// Handle different structs between forecast16 and onecall endpoints
|
// Handle different structs between forecast16 and onecall endpoints
|
||||||
var forecastList = null;
|
var forecastList = null;
|
||||||
@ -400,7 +407,7 @@ Module.register("weatherforecast", {
|
|||||||
|
|
||||||
// Since we don't want an icon from the start of the day (in the middle of the night)
|
// Since we don't want an icon from the start of the day (in the middle of the night)
|
||||||
// we update the icon as long as it's somewhere during the day.
|
// we update the icon as long as it's somewhere during the day.
|
||||||
if (hour >= 8 && hour <= 17) {
|
if (hour > dayStarts && hour < dayEnds) {
|
||||||
forecastData.icon = this.config.iconTable[forecast.weather[0].icon];
|
forecastData.icon = this.config.iconTable[forecast.weather[0].icon];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1838
tests/unit/functions/weatherforecast_data.json
Normal file
1838
tests/unit/functions/weatherforecast_data.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,6 @@
|
|||||||
/* eslint no-multi-spaces: 0 */
|
/* eslint no-multi-spaces: 0 */
|
||||||
const expect = require("chai").expect;
|
const expect = require("chai").expect;
|
||||||
|
var data = require("../functions/weatherforecast_data.json");
|
||||||
|
|
||||||
describe("Functions module weatherforecast", function () {
|
describe("Functions module weatherforecast", function () {
|
||||||
before(function () {
|
before(function () {
|
||||||
@ -63,4 +64,38 @@ describe("Functions module weatherforecast", function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("forecastIcons", function () {
|
||||||
|
Log = {
|
||||||
|
error: function () {}
|
||||||
|
};
|
||||||
|
describe("forecastIcons sunset specified", function () {
|
||||||
|
before(function () {
|
||||||
|
Module.definitions.weatherforecast.Log = {};
|
||||||
|
Module.definitions.weatherforecast.forecast = [];
|
||||||
|
Module.definitions.weatherforecast.show = Module.definitions.weatherforecast.updateDom = function () {};
|
||||||
|
Module.definitions.weatherforecast.config = Module.definitions.weatherforecast.defaults;
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`returns correct icons with sunset time`, function () {
|
||||||
|
Module.definitions.weatherforecast.processWeather(data.withSunset);
|
||||||
|
let forecastData = Module.definitions.weatherforecast.forecast;
|
||||||
|
expect(forecastData.length).to.equal(4);
|
||||||
|
expect(forecastData[2].icon).to.equal("wi-rain");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("forecastIcons sunset not specified", function () {
|
||||||
|
before(function () {
|
||||||
|
Module.definitions.weatherforecast.forecast = [];
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`returns correct icons with out sunset time`, function () {
|
||||||
|
Module.definitions.weatherforecast.processWeather(data.withoutSunset);
|
||||||
|
let forecastData = Module.definitions.weatherforecast.forecast;
|
||||||
|
expect(forecastData.length).to.equal(4);
|
||||||
|
expect(forecastData[2].icon).to.equal("wi-rain");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user