Skip to content

feat: add weather alerts to current block#29

Merged
KristjanESPERANTO merged 3 commits into
MagicMirrorModules:developfrom
mrwizard1000:mrwizard/addWeatherAlerts
Jan 25, 2026
Merged

feat: add weather alerts to current block#29
KristjanESPERANTO merged 3 commits into
MagicMirrorModules:developfrom
mrwizard1000:mrwizard/addWeatherAlerts

Conversation

@mrwizard1000

@mrwizard1000 mrwizard1000 commented Jan 24, 2026

Copy link
Copy Markdown

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 alert so that custom CSS can be applied to it.
Updated README with description.
Updated npm package for flagged vulnerability

Summary by CodeRabbit

  • New Features

    • Added weather alerts display capability. The new showAlerts configuration option allows you to enable display of weather alerts in the current weather section (disabled by default).
  • Documentation

    • Updated documentation to include the new showAlerts configuration option with its settings and default value.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 24, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR introduces weather alert functionality to the MMM-OneCallWeather module. It adds a new showAlerts configuration option, extends the data structure to capture alerts from the API response, implements conditional rendering of alerts in the UI, and updates supporting documentation.

Changes

Cohort / File(s) Summary
CSS Updates
MMM-OneCallWeather.css
Extended the text-align selector to include .alert alongside .wind-speed, enabling centered text alignment for alert elements.
Feature Implementation
MMM-OneCallWeather.js
Added showAlerts config option (default: false), populated currentWeather.alerts array from API response when available, and implemented conditional UI rendering for alerts in the current weather block.
Documentation
README.md
Added showAlerts configuration option to the documentation table with description, values, and default setting.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A bunny hops through code so neat,
With alerts dancing down the street,
When weather warnings need to show,
Config springs to life—watch them glow! 🐰⚡

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding weather alerts to the current weather block in the module.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mrwizard1000

Copy link
Copy Markdown
Author

The alerts are added at the bottom of the Current block
image

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .alert to 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 innerHTML with 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 textContent with 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);
+      }

Comment thread MMM-OneCallWeather.js
@KristjanESPERANTO KristjanESPERANTO changed the base branch from main to develop January 25, 2026 13:10
@KristjanESPERANTO KristjanESPERANTO merged commit 73550aa into MagicMirrorModules:develop Jan 25, 2026
4 of 5 checks passed
@KristjanESPERANTO KristjanESPERANTO changed the title MrWizard / Add weather alerts to current block feat: add weather alerts to current block Jan 25, 2026
@KristjanESPERANTO

Copy link
Copy Markdown
Member

@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 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants