mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
Merge pull request #2842 from MMRIZE/weather
Added outgoing notification of the weather module
This commit is contained in:
commit
8e5267d44f
@ -16,7 +16,7 @@
|
|||||||
},
|
},
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"sourceType": "module",
|
"sourceType": "module",
|
||||||
"ecmaVersion": 2018,
|
"ecmaVersion": 2020,
|
||||||
"ecmaFeatures": {
|
"ecmaFeatures": {
|
||||||
"globalReturn": true
|
"globalReturn": true
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ _This release is scheduled to be released on 2022-07-01._
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- Added the notification emitting from the weather module on infromation updated.
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -154,6 +154,15 @@ Module.register("weather", {
|
|||||||
if (this.weatherProvider.currentWeather()) {
|
if (this.weatherProvider.currentWeather()) {
|
||||||
this.sendNotification("CURRENTWEATHER_TYPE", { type: this.weatherProvider.currentWeather().weatherType.replace("-", "_") });
|
this.sendNotification("CURRENTWEATHER_TYPE", { type: this.weatherProvider.currentWeather().weatherType.replace("-", "_") });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const notificationPayload = {
|
||||||
|
currentWeather: this.weatherProvider?.currentWeatherObject?.simpleClone() ?? null,
|
||||||
|
forecastArray: this.weatherProvider?.weatherForecastArray?.map((ar) => ar.simpleClone()) ?? [],
|
||||||
|
hourlyArray: this.weatherProvider?.weatherHourlyArray?.map((ar) => ar.simpleClone()) ?? [],
|
||||||
|
locationName: this.weatherProvider?.fetchedLocationName,
|
||||||
|
providerName: this.weatherProvider.providerName
|
||||||
|
};
|
||||||
|
this.sendNotification("WEATHER_UPDATED", notificationPayload);
|
||||||
},
|
},
|
||||||
|
|
||||||
scheduleUpdate: function (delay = null) {
|
scheduleUpdate: function (delay = null) {
|
||||||
|
@ -146,6 +146,23 @@ class WeatherObject {
|
|||||||
this.sunrise = moment(times.sunrise, "X");
|
this.sunrise = moment(times.sunrise, "X");
|
||||||
this.sunset = moment(times.sunset, "X");
|
this.sunset = moment(times.sunset, "X");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clone to simple object to prevent mutating and deprecation of legacy library.
|
||||||
|
*
|
||||||
|
* Before being handed to other modules, mutable values must be cloned safely.
|
||||||
|
* Especially 'moment' object is not immutable, so original 'date', 'sunrise', 'sunset' could be corrupted or changed by other modules.
|
||||||
|
*
|
||||||
|
* @returns {object} plained object clone of original weatherObject
|
||||||
|
*/
|
||||||
|
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 ***************/
|
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user