mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
Tidy up precipitation (#3023)
Fixes #2953 This is an attempt to fix the issue with precipitation amount and percentage mixup. I have created a separate `precipitationPercentage`-variable where the probability of rain can be stored. The config options now has the old `showPrecipitationAmount` in addition to a new setting: `showPrecipitationProbability` (shows the likelihood of rain). <details> <summary>Examples</summary> ### Yr I tested the Yr weather provider for a Norwegian city Bergen that has a lot of rain. I have removed properties that are irrelevant for this demo from the config-samples below. Config: ```js { module: "weather", config: { weatherProvider: "yr", type: "current", showPrecipitationAmount: true, showPrecipitationProbability: true } }, { module: "weather", config: { weatherProvider: "yr", type: "hourly", showPrecipitationAmount: true, showPrecipitationProbability: true } }, { module: "weather", config: { weatherProvider: "yr", type: "daily", showPrecipitationAmount: true, showPrecipitationProbability: true } } ``` Result:<br/> <img width="444" alt="screenshot" src="https://user-images.githubusercontent.com/34011212/216775423-4e37345c-f915-47e5-8551-7c544ebd24b1.png"> </details> --------- Co-authored-by: Magnus Marthinsen <magmar@online.no> Co-authored-by: Veeck <github@veeck.de>
This commit is contained in:
@@ -26,6 +26,7 @@ Module.register("weather", {
|
||||
showPeriod: true,
|
||||
showPeriodUpper: false,
|
||||
showPrecipitationAmount: false,
|
||||
showPrecipitationProbability: false,
|
||||
showSun: true,
|
||||
showWindDirection: true,
|
||||
showWindDirectionAsArrow: false,
|
||||
@@ -230,7 +231,7 @@ Module.register("weather", {
|
||||
|
||||
this.nunjucksEnvironment().addFilter(
|
||||
"unit",
|
||||
function (value, type) {
|
||||
function (value, type, valueUnit) {
|
||||
if (type === "temperature") {
|
||||
value = this.roundValue(WeatherUtils.convertTemp(value, this.config.tempUnits)) + "°";
|
||||
if (this.config.degreeLabel) {
|
||||
@@ -246,11 +247,7 @@ Module.register("weather", {
|
||||
if (value === null || isNaN(value) || value === 0 || value.toFixed(2) === "0.00") {
|
||||
value = "";
|
||||
} else {
|
||||
if (this.config.weatherProvider === "ukmetoffice" || this.config.weatherProvider === "ukmetofficedatahub") {
|
||||
value += "%";
|
||||
} else {
|
||||
value = `${value.toFixed(2)} ${this.config.units === "imperial" ? "in" : "mm"}`;
|
||||
}
|
||||
value = WeatherUtils.convertPrecipitationUnit(value, valueUnit, this.config.units);
|
||||
}
|
||||
} else if (type === "humidity") {
|
||||
value += "%";
|
||||
|
Reference in New Issue
Block a user