Tom-Hirschberger / MMM-OpenWeatherForecast

Magic Mirror weather module using OpenWeather API
8 stars 2 forks source link

amount of precipitation missing for daily forecasts #2

Closed vwegert closed 2 months ago

vwegert commented 3 months ago

There is a difference in the way the expected amount of precipitation is reported in the hourly vs. the daily forecasts. Hourly:

            "pop": 0.34,
            "rain":
            {
                "1h": 0.15
            }

Daily:

            "pop": 0.48,
            "rain": 0.34,

The current code

    // --------- Precipitation ---------
    fItem.precipitation = this.formatPrecipitation(fData.pop, fData.rain ? fData.rain["1h"] : null, fData.snow ? fData.snow["1h"] : null);

apparently only considers the former case and will not produce a display of the precipitation for the dailies, even when the data is present. Suggested approach:

    // --------- Precipitation ---------
    var rain = fData.rain ? (Object.hasOwn(fData.rain, "1h") ? fData.rain["1h"] : fData.rain) : null;
    var snow = fData.snow ? (Object.hasOwn(fData.snow, "1h") ? fData.snow["1h"] : fData.snow) : null;
    fItem.precipitation = this.formatPrecipitation(fData.pop, rain, snow);
Tom-Hirschberger commented 2 months ago

Hi and sorry for the late reply. I had forgotten to set a watch to the Repository and did not get a notification about the issue.

I will take a closer look to the problem in the next days and check your solution as fast as I can

Tom-Hirschberger commented 2 months ago

As your changes look fine for me I added them and merged to the master