mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-25 23:55:07 +00:00
Add no-param-reassign from eslint (#3089)
While waiting for the easterbunny I cleaned up some bad coding practice :-) Very open for comments especially regarding the places I commented myself... --------- Co-authored-by: veeck <michael@veeck.de>
This commit is contained in:
@@ -110,13 +110,15 @@ WeatherProvider.register("yr", {
|
||||
this.getWeatherDataFromYr(weatherData?.downloadedAt)
|
||||
.then((weatherData) => {
|
||||
Log.debug("Got weather data from yr.");
|
||||
let data;
|
||||
if (weatherData) {
|
||||
this.cacheWeatherData(weatherData);
|
||||
data = weatherData;
|
||||
} else {
|
||||
//Undefined if unchanged
|
||||
weatherData = this.getWeatherDataFromCache();
|
||||
data = this.getWeatherDataFromCache();
|
||||
}
|
||||
resolve(weatherData);
|
||||
resolve(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
Log.error(err);
|
||||
@@ -266,14 +268,14 @@ WeatherProvider.register("yr", {
|
||||
this.getStellarDataFromYr(today, 2)
|
||||
.then((stellarData) => {
|
||||
if (stellarData) {
|
||||
stellarData = {
|
||||
const data = {
|
||||
today: stellarData
|
||||
};
|
||||
stellarData.tomorrow = Object.assign({}, stellarData.today);
|
||||
stellarData.today.date = today;
|
||||
stellarData.tomorrow.date = tomorrow;
|
||||
this.cacheStellarData(stellarData);
|
||||
resolve(stellarData);
|
||||
data.tomorrow = Object.assign({}, data.today);
|
||||
data.today.date = today;
|
||||
data.tomorrow.date = tomorrow;
|
||||
this.cacheStellarData(data);
|
||||
resolve(data);
|
||||
} else {
|
||||
Log.error(`Something went wrong when fetching stellar data. Responses: ${stellarData}`);
|
||||
reject(stellarData);
|
||||
|
@@ -218,29 +218,30 @@ Module.register("weather", {
|
||||
this.nunjucksEnvironment().addFilter(
|
||||
"unit",
|
||||
function (value, type, valueUnit) {
|
||||
let formattedValue;
|
||||
if (type === "temperature") {
|
||||
value = `${this.roundValue(WeatherUtils.convertTemp(value, this.config.tempUnits))}°`;
|
||||
formattedValue = `${this.roundValue(WeatherUtils.convertTemp(value, this.config.tempUnits))}°`;
|
||||
if (this.config.degreeLabel) {
|
||||
if (this.config.tempUnits === "metric") {
|
||||
value += "C";
|
||||
formattedValue += "C";
|
||||
} else if (this.config.tempUnits === "imperial") {
|
||||
value += "F";
|
||||
formattedValue += "F";
|
||||
} else {
|
||||
value += "K";
|
||||
formattedValue += "K";
|
||||
}
|
||||
}
|
||||
} else if (type === "precip") {
|
||||
if (value === null || isNaN(value) || value === 0 || value.toFixed(2) === "0.00") {
|
||||
value = "";
|
||||
formattedValue = "";
|
||||
} else {
|
||||
value = WeatherUtils.convertPrecipitationUnit(value, valueUnit, this.config.units);
|
||||
formattedValue = WeatherUtils.convertPrecipitationUnit(value, valueUnit, this.config.units);
|
||||
}
|
||||
} else if (type === "humidity") {
|
||||
value += "%";
|
||||
formattedValue = `${value}%`;
|
||||
} else if (type === "wind") {
|
||||
value = WeatherUtils.convertWind(value, this.config.windUnits);
|
||||
formattedValue = WeatherUtils.convertWind(value, this.config.windUnits);
|
||||
}
|
||||
return value;
|
||||
return formattedValue;
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
|
@@ -154,17 +154,17 @@ WeatherProvider.register = function (providerIdentifier, providerDetails) {
|
||||
* @returns {object} The new weather provider
|
||||
*/
|
||||
WeatherProvider.initialize = function (providerIdentifier, delegate) {
|
||||
providerIdentifier = providerIdentifier.toLowerCase();
|
||||
const pi = providerIdentifier.toLowerCase();
|
||||
|
||||
const provider = new WeatherProvider.providers[providerIdentifier]();
|
||||
const provider = new WeatherProvider.providers[pi]();
|
||||
const config = Object.assign({}, provider.defaults, delegate.config);
|
||||
|
||||
provider.delegate = delegate;
|
||||
provider.setConfig(config);
|
||||
|
||||
provider.providerIdentifier = providerIdentifier;
|
||||
provider.providerIdentifier = pi;
|
||||
if (!provider.providerName) {
|
||||
provider.providerName = providerIdentifier;
|
||||
provider.providerName = pi;
|
||||
}
|
||||
|
||||
return provider;
|
||||
|
@@ -32,17 +32,19 @@ const WeatherUtils = {
|
||||
* @returns {string} - A string with tha value and a unit postfix.
|
||||
*/
|
||||
convertPrecipitationUnit(value, valueUnit, outputUnit) {
|
||||
let convertedValue = value;
|
||||
let conversionUnit = valueUnit;
|
||||
if (outputUnit === "imperial") {
|
||||
if (valueUnit && valueUnit.toLowerCase() === "cm") value = value * 0.3937007874;
|
||||
else value = value * 0.03937007874;
|
||||
valueUnit = "in";
|
||||
if (valueUnit && valueUnit.toLowerCase() === "cm") convertedValue = convertedValue * 0.3937007874;
|
||||
else convertedValue = convertedValue * 0.03937007874;
|
||||
conversionUnit = "in";
|
||||
} else {
|
||||
valueUnit = valueUnit ? valueUnit : "mm";
|
||||
conversionUnit = valueUnit ? valueUnit : "mm";
|
||||
}
|
||||
|
||||
if (valueUnit === "%") return `${value.toFixed(0)} ${valueUnit}`;
|
||||
if (valueUnit === "%") return `${convertedValue.toFixed(0)} ${conversionUnit}`;
|
||||
|
||||
return `${value.toFixed(2)} ${valueUnit}`;
|
||||
return `${convertedValue.toFixed(2)} ${conversionUnit}`;
|
||||
},
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user