Use es6 notation in weather module and ukmet provider

This commit is contained in:
rejas
2021-03-21 16:58:12 +01:00
parent bda8f26511
commit 2ababa521d
2 changed files with 35 additions and 33 deletions

View File

@@ -48,6 +48,9 @@ Module.register("weather", {
// Module properties.
weatherProvider: null,
// Can be used by the provider to display location of event if nothing else is specified
firstEvent: null,
// Define required scripts.
getStyles: function () {
return ["font-awesome.css", "weather-icons.css", "weather.css"];
@@ -88,15 +91,13 @@ Module.register("weather", {
// Override notification handler.
notificationReceived: function (notification, payload, sender) {
if (notification === "CALENDAR_EVENTS") {
var senderClasses = sender.data.classes.toLowerCase().split(" ");
const senderClasses = sender.data.classes.toLowerCase().split(" ");
if (senderClasses.indexOf(this.config.calendarClass.toLowerCase()) !== -1) {
this.firstEvent = false;
for (var e in payload) {
var event = payload[e];
this.firstEvent = null;
for (let event of payload) {
if (event.location || event.geo) {
this.firstEvent = event;
//Log.log("First upcoming event with location: ", event);
Log.debug("First upcoming event with location: ", event);
break;
}
}
@@ -114,15 +115,15 @@ Module.register("weather", {
getTemplate: function () {
switch (this.config.type.toLowerCase()) {
case "current":
return `current.njk`;
return "current.njk";
case "hourly":
return `hourly.njk`;
return "hourly.njk";
case "daily":
case "forecast":
return `forecast.njk`;
return "forecast.njk";
//Make the invalid values use the "Loading..." from forecast
default:
return `forecast.njk`;
return "forecast.njk";
}
},
@@ -152,7 +153,7 @@ Module.register("weather", {
},
scheduleUpdate: function (delay = null) {
var nextLoad = this.config.updateInterval;
let nextLoad = this.config.updateInterval;
if (delay !== null && delay >= 0) {
nextLoad = delay;
}
@@ -176,8 +177,8 @@ Module.register("weather", {
},
roundValue: function (temperature) {
var decimals = this.config.roundTemp ? 0 : 1;
var roundValue = parseFloat(temperature).toFixed(decimals);
const decimals = this.config.roundTemp ? 0 : 1;
const roundValue = parseFloat(temperature).toFixed(decimals);
return roundValue === "-0" ? 0 : roundValue;
},
@@ -272,8 +273,8 @@ Module.register("weather", {
if (this.config.fadePoint < 0) {
this.config.fadePoint = 0;
}
var startingPoint = numSteps * this.config.fadePoint;
var numFadesteps = numSteps - startingPoint;
const startingPoint = numSteps * this.config.fadePoint;
const numFadesteps = numSteps - startingPoint;
if (currentStep >= startingPoint) {
return 1 - (currentStep - startingPoint) / numFadesteps;
} else {