Added outgoing notification of the weather module#2842
Added outgoing notification of the weather module#2842MichMich merged 5 commits intoMagicMirrorOrg:developfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #2842 +/- ##
========================================
Coverage 65.15% 65.15%
========================================
Files 8 8
Lines 287 287
========================================
Hits 187 187
Misses 100 100 Continue to review full report at Codecov.
|
|
Hmmm... The Is this not acceptable? |
modules/default/weather/weather.js
Outdated
| forecast: this.weatherProvider?.weatherForecastArray?.map((ar) => ar.simpleClone()) ?? [], | ||
| hourly: this.weatherProvider?.weatherHourlyArray?.map((ar) => ar.simpleClone()) ?? [], | ||
| location: this.weatherProvider?.fetchedLocationName, | ||
| provider: this.weatherProvider.providerName |
There was a problem hiding this comment.
maybe also call it "providerName" to avoid misunderstanding
There was a problem hiding this comment.
good point. I'll modify it.
It snot node but eslint that fails due to the optional chaining. As can be read here: |
Than ks for hints. |
modules/default/weather/weather.js
Outdated
| this.sendNotification("CURRENTWEATHER_TYPE", { type: this.weatherProvider.currentWeather().weatherType.replace("-", "_") }); | ||
| } | ||
|
|
||
| let notificationPayload = { |
| * | ||
| * @returns {object} simple object cloned. | ||
| */ | ||
| simpleClone() { |
There was a problem hiding this comment.
since there are so many js features used in this method (which might confuse beginners) would be nice to have an example of what this does in the jsdoc.
There was a problem hiding this comment.
I'm not sure a good example could be possible because this feature is only for making a safe-immutable payload of notification.
Anyway, I added some description more.
There was a problem hiding this comment.
There was a problem hiding this comment.
By the way, all the payload of original default modules is mutable and not safe from modifying by recipient modules I think that could be a risk in some cases.
There was a problem hiding this comment.
By the way, all the payload of original default modules is mutable and not safe from modifying by recipient modules I think that could be a risk in some cases.
so thats why you added this method?
There was a problem hiding this comment.
Also: I am wondering if there isnt a lodash method that would do the same thing?
There was a problem hiding this comment.
@eouia @rejas all the default modules send notifications of their data so that others might compose new apps.. BUT since the new weather module combined current weather and forecast, it (the new module) does NOT broadcast the forecast info when running in forecast mode.
yes, it only published the CURRENTWEATHER_TYPE, so that the compliments module can react to it ( I think I added that back in the days) Maybe its a good idea to remove that call and broadcast only the whole weather object (instead of just the CURRENTWEATHER_TYPE)?
There was a problem hiding this comment.
moment object is not immutable and unsafe.
For example; In case of ‘weatherObject.sunrise’ is handed to other module as payload directly, the 3rd party module can manipulate the object;
/* In other module’s receivedNotification function */
let afterSunRise = payload.sunrise.add(30, ‘minute’)But by this execution, the original this.weatherProvider.currentWeatherObject.sunrise Will be changed. Usually this is a bad side-effect unintentional.
There was a problem hiding this comment.
And I prefer pure JS itself as far as possible, instead of being dependent on 3rd party library in the browser.
Different with usual nodeJS app, MM on the browser is not modular. All the 3rd party libraries are loaded get global scope. It is not comfortable for me with that. :)
There was a problem hiding this comment.
I dont mind 3rd party libraries like lodash, sicne they are well tested and we already use it in here. But your code your choice :-)
|
|
||
| ### Added | ||
|
|
||
| - Added the notification emitting from the weather module on infromation updated. |
There was a problem hiding this comment.
Typo: information
The current
weathermodule seems no notification emission.Added
WEATHER_UPDATEDnotification when new weather information is provided.When this PR is accepted, I'll modify wiki page of MM manual.