mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-07-06 15:48: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:
parent
cc1d4ab240
commit
56736786fd
@ -28,6 +28,7 @@ _This release is scheduled to be released on 2024-10-01._
|
|||||||
- Fixed `checks` badge in README.md
|
- Fixed `checks` badge in README.md
|
||||||
- [weather] Fixed issue with the UK Met Office provider following a change in their API paths and header info.
|
- [weather] Fixed issue with the UK Met Office provider following a change in their API paths and header info.
|
||||||
- [core] add check for node_helper loading for multiple instances of same module (#3502)
|
- [core] add check for node_helper loading for multiple instances of same module (#3502)
|
||||||
|
- [weather] Fixed issue for respecting unit config on broadcasted notifications
|
||||||
|
|
||||||
## [2.28.0] - 2024-07-01
|
## [2.28.0] - 2024-07-01
|
||||||
|
|
||||||
|
@ -170,12 +170,19 @@ Module.register("weather", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const notificationPayload = {
|
const notificationPayload = {
|
||||||
currentWeather: this.weatherProvider?.currentWeatherObject?.simpleClone() ?? null,
|
currentWeather: this.config.units === "imperial"
|
||||||
forecastArray: this.weatherProvider?.weatherForecastArray?.map((ar) => ar.simpleClone()) ?? [],
|
? WeatherUtils.convertWeatherObjectToImperial(this.weatherProvider?.currentWeatherObject?.simpleClone()) ?? null
|
||||||
hourlyArray: this.weatherProvider?.weatherHourlyArray?.map((ar) => ar.simpleClone()) ?? [],
|
: this.weatherProvider?.currentWeatherObject?.simpleClone() ?? null,
|
||||||
|
forecastArray: this.config.units === "imperial"
|
||||||
|
? this.weatherProvider?.weatherForecastArray?.map((ar) => WeatherUtils.convertWeatherObjectToImperial(ar.simpleClone())) ?? []
|
||||||
|
: this.weatherProvider?.weatherForecastArray?.map((ar) => ar.simpleClone()) ?? [],
|
||||||
|
hourlyArray: this.config.units === "imperial"
|
||||||
|
? this.weatherProvider?.weatherHourlyArray?.map((ar) => WeatherUtils.convertWeatherObjectToImperial(ar.simpleClone())) ?? []
|
||||||
|
: this.weatherProvider?.weatherHourlyArray?.map((ar) => ar.simpleClone()) ?? [],
|
||||||
locationName: this.weatherProvider?.fetchedLocationName,
|
locationName: this.weatherProvider?.fetchedLocationName,
|
||||||
providerName: this.weatherProvider.providerName
|
providerName: this.weatherProvider.providerName
|
||||||
};
|
};
|
||||||
|
|
||||||
this.sendNotification("WEATHER_UPDATED", notificationPayload);
|
this.sendNotification("WEATHER_UPDATED", notificationPayload);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -30,8 +30,7 @@ const WeatherUtils = {
|
|||||||
let convertedValue = value;
|
let convertedValue = value;
|
||||||
let conversionUnit = valueUnit;
|
let conversionUnit = valueUnit;
|
||||||
if (outputUnit === "imperial") {
|
if (outputUnit === "imperial") {
|
||||||
if (valueUnit && valueUnit.toLowerCase() === "cm") convertedValue = convertedValue * 0.3937007874;
|
convertedValue = this.convertPrecipitationToInch(value, valueUnit);
|
||||||
else convertedValue = convertedValue * 0.03937007874;
|
|
||||||
conversionUnit = "in";
|
conversionUnit = "in";
|
||||||
} else {
|
} else {
|
||||||
conversionUnit = valueUnit ? valueUnit : "mm";
|
conversionUnit = valueUnit ? valueUnit : "mm";
|
||||||
@ -40,6 +39,17 @@ const WeatherUtils = {
|
|||||||
return `${convertedValue.toFixed(2)} ${conversionUnit}`;
|
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
|
* Convert temp (from degrees C) into imperial or metric unit depending on
|
||||||
* your config
|
* your config
|
||||||
@ -129,6 +139,28 @@ const WeatherUtils = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ((feelsLike - 32) * 5) / 9;
|
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user