mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 03:39:55 +00:00
Use es6 notation in weatherprovider
This commit is contained in:
parent
376b65c749
commit
838eed2630
@ -74,7 +74,7 @@ WeatherProvider.register("smhi", {
|
|||||||
getClosestToCurrentTime(times) {
|
getClosestToCurrentTime(times) {
|
||||||
let now = moment();
|
let now = moment();
|
||||||
let minDiff = undefined;
|
let minDiff = undefined;
|
||||||
for (time of times) {
|
for (const time of times) {
|
||||||
let diff = Math.abs(moment(time.validTime).diff(now));
|
let diff = Math.abs(moment(time.validTime).diff(now));
|
||||||
if (!minDiff || diff < Math.abs(moment(minDiff.validTime).diff(now))) {
|
if (!minDiff || diff < Math.abs(moment(minDiff.validTime).diff(now))) {
|
||||||
minDiff = time;
|
minDiff = time;
|
||||||
@ -149,13 +149,13 @@ WeatherProvider.register("smhi", {
|
|||||||
* @param coordinates
|
* @param coordinates
|
||||||
*/
|
*/
|
||||||
convertWeatherDataGroupedByDay(allWeatherData, coordinates) {
|
convertWeatherDataGroupedByDay(allWeatherData, coordinates) {
|
||||||
var currentWeather;
|
let currentWeather;
|
||||||
let result = [];
|
let result = [];
|
||||||
|
|
||||||
let allWeatherObjects = this.fillInGaps(allWeatherData).map((weatherData) => this.convertWeatherDataToObject(weatherData, coordinates));
|
let allWeatherObjects = this.fillInGaps(allWeatherData).map((weatherData) => this.convertWeatherDataToObject(weatherData, coordinates));
|
||||||
var dayWeatherTypes = [];
|
let dayWeatherTypes = [];
|
||||||
|
|
||||||
for (weatherObject of allWeatherObjects) {
|
for (const weatherObject of allWeatherObjects) {
|
||||||
//If its the first object or if a day change we need to reset the summary object
|
//If its the first object or if a day change we need to reset the summary object
|
||||||
if (!currentWeather || !currentWeather.date.isSame(weatherObject.date, "day")) {
|
if (!currentWeather || !currentWeather.date.isSame(weatherObject.date, "day")) {
|
||||||
currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||||
@ -216,12 +216,12 @@ WeatherProvider.register("smhi", {
|
|||||||
*/
|
*/
|
||||||
fillInGaps(data) {
|
fillInGaps(data) {
|
||||||
let result = [];
|
let result = [];
|
||||||
for (var i = 1; i < data.length; i++) {
|
for (const i = 1; i < data.length; i++) {
|
||||||
let to = moment(data[i].validTime);
|
let to = moment(data[i].validTime);
|
||||||
let from = moment(data[i - 1].validTime);
|
let from = moment(data[i - 1].validTime);
|
||||||
let hours = moment.duration(to.diff(from)).asHours();
|
let hours = moment.duration(to.diff(from)).asHours();
|
||||||
// For each hour add a datapoint but change the validTime
|
// For each hour add a datapoint but change the validTime
|
||||||
for (var j = 0; j < hours; j++) {
|
for (const j = 0; j < hours; j++) {
|
||||||
let current = Object.assign({}, data[i]);
|
let current = Object.assign({}, data[i]);
|
||||||
current.validTime = from.clone().add(j, "hours").toISOString();
|
current.validTime = from.clone().add(j, "hours").toISOString();
|
||||||
result.push(current);
|
result.push(current);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
* This class is the blueprint for a weather provider.
|
* This class is the blueprint for a weather provider.
|
||||||
*/
|
*/
|
||||||
var WeatherProvider = Class.extend({
|
const WeatherProvider = Class.extend({
|
||||||
// Weather Provider Properties
|
// Weather Provider Properties
|
||||||
providerName: null,
|
providerName: null,
|
||||||
defaults: {},
|
defaults: {},
|
||||||
@ -114,7 +114,7 @@ var WeatherProvider = Class.extend({
|
|||||||
// A convenience function to make requests. It returns a promise.
|
// A convenience function to make requests. It returns a promise.
|
||||||
fetchData: function (url, method = "GET", data = null) {
|
fetchData: function (url, method = "GET", data = null) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
var request = new XMLHttpRequest();
|
const request = new XMLHttpRequest();
|
||||||
request.open(method, url, true);
|
request.open(method, url, true);
|
||||||
request.onreadystatechange = function () {
|
request.onreadystatechange = function () {
|
||||||
if (this.readyState === 4) {
|
if (this.readyState === 4) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user