mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-22 05:07:05 +00:00
Bug in Weather Units for Broadcasted Notification (#3519)
This PR resolve Issue number #3419 . I have added the method `convertWeatherObjectToImperial()` which converts the units of the `notificationPayload` to imperial if needed, in order to pass the object in `sendNotification()`. --------- Co-authored-by: veeck <michael.veeck@nebenan.de>
This commit is contained in:
@@ -30,8 +30,7 @@ const WeatherUtils = {
|
||||
let convertedValue = value;
|
||||
let conversionUnit = valueUnit;
|
||||
if (outputUnit === "imperial") {
|
||||
if (valueUnit && valueUnit.toLowerCase() === "cm") convertedValue = convertedValue * 0.3937007874;
|
||||
else convertedValue = convertedValue * 0.03937007874;
|
||||
convertedValue = this.convertPrecipitationToInch(value, valueUnit);
|
||||
conversionUnit = "in";
|
||||
} else {
|
||||
conversionUnit = valueUnit ? valueUnit : "mm";
|
||||
@@ -40,6 +39,17 @@ const WeatherUtils = {
|
||||
return `${convertedValue.toFixed(2)} ${conversionUnit}`;
|
||||
},
|
||||
|
||||
/**
|
||||
* Convert precipitation value into inch
|
||||
* @param {number} value the precipitation value for convert
|
||||
* @param {string} valueUnit can be 'mm' or 'cm'
|
||||
* @returns {number} the converted precipitation value
|
||||
*/
|
||||
convertPrecipitationToInch (value, valueUnit) {
|
||||
if (valueUnit && valueUnit.toLowerCase() === "cm") return value * 0.3937007874;
|
||||
else return value * 0.03937007874;
|
||||
},
|
||||
|
||||
/**
|
||||
* Convert temp (from degrees C) into imperial or metric unit depending on
|
||||
* your config
|
||||
@@ -129,6 +139,28 @@ const WeatherUtils = {
|
||||
}
|
||||
|
||||
return ((feelsLike - 32) * 5) / 9;
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts the Weather Object's values into imperial unit
|
||||
* @param {object} weatherObject the weather object
|
||||
* @returns {object} the weather object with converted values to imperial
|
||||
*/
|
||||
convertWeatherObjectToImperial (weatherObject) {
|
||||
if (!weatherObject || Object.keys(weatherObject).length === 0) return null;
|
||||
|
||||
let imperialWeatherObject = { ...weatherObject };
|
||||
|
||||
if (imperialWeatherObject) {
|
||||
if (imperialWeatherObject.feelsLikeTemp) imperialWeatherObject.feelsLikeTemp = this.convertTemp(imperialWeatherObject.feelsLikeTemp, "imperial");
|
||||
if (imperialWeatherObject.maxTemperature) imperialWeatherObject.maxTemperature = this.convertTemp(imperialWeatherObject.maxTemperature, "imperial");
|
||||
if (imperialWeatherObject.minTemperature) imperialWeatherObject.minTemperature = this.convertTemp(imperialWeatherObject.minTemperature, "imperial");
|
||||
if (imperialWeatherObject.precipitationAmount) imperialWeatherObject.precipitationAmount = this.convertPrecipitationToInch(imperialWeatherObject.precipitationAmount, imperialWeatherObject.precipitationUnits);
|
||||
if (imperialWeatherObject.temperature) imperialWeatherObject.temperature = this.convertTemp(imperialWeatherObject.temperature, "imperial");
|
||||
if (imperialWeatherObject.windSpeed) imperialWeatherObject.windSpeed = this.convertWind(imperialWeatherObject.windSpeed, "imperial");
|
||||
}
|
||||
|
||||
return imperialWeatherObject;
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user