mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-26 08:01:29 +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:
@@ -15,7 +15,8 @@ let config = {
|
||||
location: "Munich",
|
||||
mockData: '"#####WEATHERDATA#####"',
|
||||
weatherEndpoint: "/forecast/daily",
|
||||
decimalSymbol: "_"
|
||||
decimalSymbol: "_",
|
||||
showPrecipitationAmount: true
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@@ -0,0 +1,27 @@
|
||||
/* MagicMirror² Test config hourly weather
|
||||
*
|
||||
* By rejas https://github.com/rejas
|
||||
* MIT Licensed.
|
||||
*/
|
||||
let config = {
|
||||
timeFormat: 12,
|
||||
|
||||
modules: [
|
||||
{
|
||||
module: "weather",
|
||||
position: "bottom_bar",
|
||||
config: {
|
||||
type: "hourly",
|
||||
location: "Berlin",
|
||||
mockData: '"#####WEATHERDATA#####"',
|
||||
showPrecipitationAmount: true,
|
||||
showPrecipitationProbability: true
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") {
|
||||
module.exports = config;
|
||||
}
|
@@ -81,16 +81,29 @@ describe("Weather module: Weather Forecast", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Forecast weather units", () => {
|
||||
describe("Forecast weather with imperial units", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_units.js", {});
|
||||
});
|
||||
|
||||
const temperatures = ["75_9°", "69_8°", "73_2°", "74_1°", "69_1°"];
|
||||
for (const [index, temp] of temperatures.entries()) {
|
||||
it("should render custom decimalSymbol = '_' for temp " + temp, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
|
||||
});
|
||||
}
|
||||
describe("Temperature units", () => {
|
||||
const temperatures = ["75_9°", "69_8°", "73_2°", "74_1°", "69_1°"];
|
||||
for (const [index, temp] of temperatures.entries()) {
|
||||
it("should render custom decimalSymbol = '_' for temp " + temp, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Precipitation units", () => {
|
||||
const precipitations = [undefined, "0.10 in"];
|
||||
for (const [index, precipitation] of precipitations.entries()) {
|
||||
if (precipitation) {
|
||||
it("should render precipitation value " + precipitation, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td.precipitationAmount`, precipitation);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -33,4 +33,32 @@ describe("Weather module: Weather Hourly Forecast", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("Show precipitations", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/hourlyweather_showPrecipitation.js", {});
|
||||
});
|
||||
|
||||
describe("Shows precipitation amount", () => {
|
||||
const amounts = [undefined, undefined, undefined, "0.13 mm", "0.13 mm"];
|
||||
for (const [index, amount] of amounts.entries()) {
|
||||
if (amount) {
|
||||
it(`should render precipitation amount ${amount}`, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td.precipitationAmount`, amount);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
describe("Shows precipitation propability", () => {
|
||||
const propabilities = [undefined, undefined, "12%", "36%", "44%"];
|
||||
for (const [index, pop] of propabilities.entries()) {
|
||||
if (pop) {
|
||||
it(`should render propability ${pop}`, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td.precipitationProbability`, pop);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -64,7 +64,9 @@
|
||||
],
|
||||
"speed": 2.21,
|
||||
"deg": 81,
|
||||
"clouds": 100
|
||||
"clouds": 100,
|
||||
"pop": 0.7,
|
||||
"rain": 2.51
|
||||
},
|
||||
{
|
||||
"dt": 1568545200,
|
||||
|
45
tests/unit/modules/default/weather/weather_utils_spec.js
Normal file
45
tests/unit/modules/default/weather/weather_utils_spec.js
Normal file
@@ -0,0 +1,45 @@
|
||||
const weather = require("../../../../../modules/default/weather/weatherutils.js");
|
||||
|
||||
describe("Weather utils tests", () => {
|
||||
describe("convertPrecipitationUnit tests", () => {
|
||||
it("Should keep value and unit if outputUnit is undefined", () => {
|
||||
const values = [1, 2];
|
||||
const units = ["mm", "cm"];
|
||||
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
var result = weather.convertPrecipitationUnit(values[i], units[i], undefined);
|
||||
expect(result).toBe(`${values[i].toFixed(2)} ${units[i]}`);
|
||||
}
|
||||
});
|
||||
|
||||
it("Should keep value and unit if outputUnit is metric", () => {
|
||||
const values = [1, 2];
|
||||
const units = ["mm", "cm"];
|
||||
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
var result = weather.convertPrecipitationUnit(values[i], units[i], "metric");
|
||||
expect(result).toBe(`${values[i].toFixed(2)} ${units[i]}`);
|
||||
}
|
||||
});
|
||||
|
||||
it("Should use mm unit if input unit is undefined", () => {
|
||||
const values = [1, 2];
|
||||
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
var result = weather.convertPrecipitationUnit(values[i], undefined, "metric");
|
||||
expect(result).toBe(`${values[i].toFixed(2)} mm`);
|
||||
}
|
||||
});
|
||||
|
||||
it("Should convert value and unit if outputUnit is imperial", () => {
|
||||
const values = [1, 2];
|
||||
const units = ["mm", "cm"];
|
||||
const expectedValues = [0.04, 0.79];
|
||||
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
var result = weather.convertPrecipitationUnit(values[i], units[i], "imperial");
|
||||
expect(result).toBe(`${expectedValues[i]} in`);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user