jinserk / MMM-2Day-NOAA-Forecast

MIT License
7 stars 6 forks source link

Error fetching forecast data #4

Open davidrea opened 2 weeks ago

davidrea commented 2 weeks ago

After working well for a few months, this week the module stopped successfully updating. On reviewing logs, it seems to be having trouble parsing the response from the NOAA API:

0|MagicMirror  | [2024-06-27 22:38:59.821] [ERROR] Error fetching forecast data: TypeError: Cannot read properties of undefined (reading 'value')
0|MagicMirror  |     at /home/magicmirror/MagicMirror/modules/MMM-2Day-NOAA-Forecast/node_helper.js:84:41
0|MagicMirror  |     at Array.forEach (<anonymous>)
0|MagicMirror  |     at Class.parseData (/home/magicmirror/MagicMirror/modules/MMM-2Day-NOAA-Forecast/node_helper.js:73:22)
0|MagicMirror  |     at /home/magicmirror/MagicMirror/modules/MMM-2Day-NOAA-Forecast/node_helper.js:46:30
0|MagicMirror  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
taylornoss commented 1 week ago

@davidrea - it looks like the API is no longer returning a relative humidity value in the response data for the forecast.

For a quick fix, add a check to only parse the humidity if it exists in the parseData function in the node_helper.js file: humid: element.relativeHumidity?.value

Now if there is no humidity value present, it will default to undefined. This will at least let the data get parsed, although your humidity line in the forecast will now show undefined.

To fix that, add a conditional to the lines that add the humidity to the display. In MMM-2Day-NOAA-Forecast.js in the getDom function, wrap the humidity related elements in a check if the humidity value is not undefined:

if(this.forecast[i]?.humid != undefined){
     forecastDetail.appendChild(humidIcon);
     forecastDetail.appendChild(humidText);
     forecastDetail.appendChild(humidBr);
}
davidrea commented 1 week ago

Thanks for the guidance @taylornoss!

Looks like there is an open pull request that disables the humidity function since it is officially deprecated by NWS: https://github.com/jinserk/MMM-2Day-NOAA-Forecast/pull/3

I added "Closes #4" to the comments of the PR but not sure if that'll auto-close this if/once @jinserk merges it.