Skip to content

Added outgoing notification of the weather module#2842

Merged
MichMich merged 5 commits intoMagicMirrorOrg:developfrom
MMRIZE:weather
May 18, 2022
Merged

Added outgoing notification of the weather module#2842
MichMich merged 5 commits intoMagicMirrorOrg:developfrom
MMRIZE:weather

Conversation

@eouia
Copy link
Contributor

@eouia eouia commented Apr 26, 2022

The current weather module seems no notification emission.

Added WEATHER_UPDATED notification when new weather information is provided.

When this PR is accepted, I'll modify wiki page of MM manual.

@codecov-commenter
Copy link

Codecov Report

Merging #2842 (df0f048) into develop (439690b) will not change coverage.
The diff coverage is n/a.

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

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 439690b...df0f048. Read the comment docs.

@eouia
Copy link
Contributor Author

eouia commented Apr 26, 2022

Hmmm... The optional chaining(?.) made the test fail.
Optional chaining has been adopted as standards since NodeJS 14 and ECMA 2020 (Chrome 80 and all the current stable browsers.)

Is this not acceptable?

forecast: this.weatherProvider?.weatherForecastArray?.map((ar) => ar.simpleClone()) ?? [],
hourly: this.weatherProvider?.weatherHourlyArray?.map((ar) => ar.simpleClone()) ?? [],
location: this.weatherProvider?.fetchedLocationName,
provider: this.weatherProvider.providerName
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe also call it "providerName" to avoid misunderstanding

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. I'll modify it.

@rejas
Copy link
Collaborator

rejas commented Apr 26, 2022

Hmmm... The optional chaining(?.) made the test fail. Optional changing has been adopted as standards since NodeJS 14 and ECMA 2020 (Chrome 80 and all the current stable browsers.)

Is this not acceptable?

It snot node but eslint that fails due to the optional chaining. As can be read here:
https://eslint.org/blog/2020/07/eslint-v7.5.0-released
you need to use

    "ecmaVersion": 2020

@eouia
Copy link
Contributor Author

eouia commented Apr 26, 2022

Hmmm... The optional chaining(?.) made the test fail. Optional changing has been adopted as standards since NodeJS 14 and ECMA 2020 (Chrome 80 and all the current stable browsers.)
Is this not acceptable?

It snot node but eslint that fails due to the optional chaining. As can be read here: https://eslint.org/blog/2020/07/eslint-v7.5.0-released you need to use

    "ecmaVersion": 2020

Than ks for hints.

this.sendNotification("CURRENTWEATHER_TYPE", { type: this.weatherProvider.currentWeather().weatherType.replace("-", "_") });
}

let notificationPayload = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can be a const

*
* @returns {object} simple object cloned.
*/
simpleClone() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

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?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also: I am wondering if there isnt a lodash method that would do the same thing?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@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)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

@eouia eouia Apr 26, 2022

Choose a reason for hiding this comment

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

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. :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo: information

@MichMich MichMich merged commit 8e5267d into MagicMirrorOrg:develop May 18, 2022
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.

6 participants