feat: add weather alerts to current block#29
Conversation
📝 WalkthroughWalkthroughThis PR introduces weather alert functionality to the MMM-OneCallWeather module. It adds a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@MMM-OneCallWeather.js`:
- Around line 141-142: The precipitation property is computed from current.rain
and current.snow but current is an empty array, and OpenWeatherMap uses nested
"1h" fields; update the precipitation calculation to safely read numbers from
current.rain["1h"] and current.snow["1h"] (falling back to 0 when missing)
instead of current.rain/current.snow directly, e.g. replace the existing
precipitation: current.rain + current.snow expression with a safe sum using
current?.rain?.['1h'] || 0 and current?.snow?.['1h'] || 0 (reference the current
variable and the precipitation property being set).
🧹 Nitpick comments (2)
MMM-OneCallWeather.css (1)
75-78: LGTM!Adding
.alertto the centered text selectors is appropriate and follows the existing CSS structure.Consider adding distinct visual styling for weather alerts (e.g., a warning color or icon) to draw user attention. This could be a follow-up enhancement.
MMM-OneCallWeather.js (1)
654-670: Alerts rendering logic is correct.The implementation properly checks configuration and array length before rendering. One consideration: using
innerHTMLwith API data (weatherAlert.event) could theoretically be an XSS vector if the API returned malicious content. Since OpenWeatherMap is a trusted source, this is low risk.For a more defensive approach, consider using
textContentwith separate elements per alert:♻️ Optional safer alternative
- let alertText = ""; - for (const weatherAlert of currentWeather.alerts) { - if (alertText !== "") { - alertText += "<br />"; - } - alertText += weatherAlert.event; - } - currentCell4.innerHTML = alertText; + for (const weatherAlert of currentWeather.alerts) { + const alertDiv = document.createElement("div"); + alertDiv.textContent = weatherAlert.event; + currentCell4.appendChild(alertDiv); + }
73550aa
into
MagicMirrorModules:develop
|
@mrwizard1000 Thanks for this new useful feature! 👏 I refactored it a bit and fixed it so that there are no problems when you have multiple instances of the module. I also enabled the feature by default. I think that's the better choice so that users can see this useful function. If it bothers anyone, they can always disable it 🙂 |

Adds a config option (default is false to not affect existing installations) that will show any current weather alerts for the configured location.
Adds a new CSS style
alertso that custom CSS can be applied to it.Updated README with description.
Updated npm package for flagged vulnerability
Summary by CodeRabbit
New Features
showAlertsconfiguration option allows you to enable display of weather alerts in the current weather section (disabled by default).Documentation
showAlertsconfiguration option with its settings and default value.✏️ Tip: You can customize this high-level summary in your review settings.