mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
Added outgoing notification
This commit is contained in:
parent
439690b981
commit
df0f048ecc
@ -11,6 +11,8 @@ _This release is scheduled to be released on 2022-07-01._
|
||||
|
||||
### Added
|
||||
|
||||
- Added the notification emitting from the weather module on infromation updated.
|
||||
|
||||
### Updated
|
||||
|
||||
### Fixed
|
||||
|
@ -154,6 +154,15 @@ Module.register("weather", {
|
||||
if (this.weatherProvider.currentWeather()) {
|
||||
this.sendNotification("CURRENTWEATHER_TYPE", { type: this.weatherProvider.currentWeather().weatherType.replace("-", "_") });
|
||||
}
|
||||
|
||||
let notificationPayload = {
|
||||
current: this.weatherProvider?.currentWeatherObject?.simpleClone() ?? null,
|
||||
forecast: this.weatherProvider?.weatherForecastArray?.map((ar) => ar.simpleClone()) ?? [],
|
||||
hourly: this.weatherProvider?.weatherHourlyArray?.map((ar) => ar.simpleClone()) ?? [],
|
||||
location: this.weatherProvider?.fetchedLocationName,
|
||||
provider: this.weatherProvider.providerName
|
||||
};
|
||||
this.sendNotification("WEATHER_UPDATED", notificationPayload);
|
||||
},
|
||||
|
||||
scheduleUpdate: function (delay = null) {
|
||||
|
@ -146,6 +146,20 @@ class WeatherObject {
|
||||
this.sunrise = moment(times.sunrise, "X");
|
||||
this.sunset = moment(times.sunset, "X");
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone to simple object to prevent mutating and deprecated legacy library.
|
||||
*
|
||||
* @return {object} simple object cloned.
|
||||
*/
|
||||
simpleClone() {
|
||||
const toFlat = ["date", "sunrise", "sunset"];
|
||||
let clone = { ...this };
|
||||
for (const prop of toFlat) {
|
||||
clone[prop] = clone?.[prop]?.valueOf() ?? clone?.[prop];
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
|
Loading…
x
Reference in New Issue
Block a user