Skip to content

Commit 73550aa

Browse files
authored
feat: add weather alerts to current block (#29)
1 parent aa97f58 commit 73550aa

4 files changed

Lines changed: 32 additions & 5 deletions

File tree

MMM-OneCallWeather.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
& .day,
7373
& .max-temp,
7474
& .min-temp,
75-
& .wind-speed {
75+
& .wind-speed,
76+
& .alert {
7677
text-align: center;
7778
}
7879

MMM-OneCallWeather.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Module.register("MMM-OneCallWeather", {
3737
roundTemp: true,
3838
showCurrent: true,
3939
showForecast: true,
40+
showAlerts: false,
4041
forecastLayout: "columns", // "columns" (days as columns) or "rows" (days as rows)
4142
arrangement: "vertical", // "vertical" (forecast below current) or "horizontal" (forecast next to current)
4243

@@ -137,8 +138,14 @@ Module.register("MMM-OneCallWeather", {
137138
weatherType: this.convertWeatherType(data.current.weather[0].icon),
138139
humidity: data.current.humidity,
139140
feelsLikeTemp: data.current.feels_like.toFixed(1),
140-
precipitation: current.rain + current.snow
141+
precipitation: current.rain + current.snow,
142+
alerts: []
141143
};
144+
145+
if (Object.hasOwn(data, "alerts")) {
146+
currently.alerts = data.alerts;
147+
}
148+
142149
current.push(currently);
143150
Log.debug(`current weather is ${JSON.stringify(currently)}`);
144151
}
@@ -644,6 +651,24 @@ Module.register("MMM-OneCallWeather", {
644651
currentRow3.appendChild(currentCell3);
645652
table.appendChild(currentRow3);
646653

654+
// Row 4: Current weather alerts
655+
if (this.config.showAlerts && currentWeather.alerts.length > 0) {
656+
const currentRow4 = document.createElement("tr");
657+
const currentCell4 = document.createElement("td");
658+
currentCell4.colSpan = colspan;
659+
currentCell4.className = "alert";
660+
let alertText = "";
661+
for (const weatherAlert of currentWeather.alerts) {
662+
if (alertText !== "") {
663+
alertText += "<br />";
664+
}
665+
alertText += weatherAlert.event;
666+
}
667+
currentCell4.innerHTML = alertText;
668+
currentRow4.appendChild(currentCell4);
669+
table.appendChild(currentRow4);
670+
}
671+
647672
return table;
648673
},
649674

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ The following properties can be configured:
9292
| `windUnits` | The units to use for wind speed.<br><br>**Possible values:** `"mph"` (miles per hour), `"kmph"` (kilometers per hour), `"ms"` (meters per second)<br>**Default value:** `"mph"`<br>This value is optional. By default the weatherforecast module will display wind speed in miles per hour. |
9393
| `roundTemp` | Round temperature values to nearest integer.<br><br>**Possible values:** `true` (round to integer) or `false` (display exact value with decimal point)<br>**Default value:** `false` |
9494
| `showCurrent` | Show the current weather section.<br><br>**Possible values:** `true` or `false`<br>**Default value:** `true` |
95+
| `showAlerts` | Show the current weather alerts.<br><br>**Possible values:** `true` or `false`<br>**Default value:** `false` |
9596
| `showForecast` | Show the forecast section.<br><br>**Possible values:** `true` or `false`<br>**Default value:** `true` |
9697
| `forecastLayout` | Defines how the forecast is structured internally.<br><br>**Possible values:** `"columns"` (days displayed as table columns), `"rows"` (days displayed as table rows)<br>**Default value:** `"columns"` |
9798
| `arrangement` | How current weather and forecast are positioned relative to each other (only relevant when both `showCurrent` and `showForecast` are `true`).<br><br>**Possible values:** `"vertical"` (forecast below current weather), `"horizontal"` (forecast next to current weather)<br>**Default value:** `"vertical"` |

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)