A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.
  • 0 Votes
    1 Posts
    685 Views
    R

    greetings,
    I’m building my first little module which sends a notification to Alert module by

    this.sendNotification("SHOW_ALERT", {title: "blah", imageFA: 'bullhorn', message: "blah", timer: 5000});

    the problem is any icon in imageFA except bullhorn isn’t shown even with adding the proper

    getStyles: function() { return ['font-awesome.css']; },

    to my_module.js file so the question is, does alert module fully handle the notification payload (which contains imageFA data) if so looks like there is a problem with the default module?, or something missing has to be configured first in my module??

  • 0 Votes
    5 Posts
    4k Views
    I

    @Squawk09 - it is not a requirement to log when receiving notifications, but it can be useful when debugging. To prove you are receiving the notification, change the line to Log.log('The current temperature is ' + this.temp); and look in the browsers console and you should see the temperature displayed when it is sent from the current weather module.

    Once you have confirmed that your module is receiving the notifications, you can then move on to displaying the temperature.

    The trick is to understand the sequence of events that occur and how they affect your module. In your case the functions in your modules are currently fired in the following order:

    start notificationReceived (ALL_MODULES_STARTED) getDom notificationReceived (DOM_OBJECTS_CREATED) notificationReceived (Temperature)

    The result is that your getDom function is called before the Temperature notification is received, so this.temp hasn’t been set yet.

    Since you cannot control the order in which the modules are loaded, or when the Temperature notification is sent by the current weather module, you need to tell your module to call the getDom function again, after the Temperature notification has been received.

    To do this, change your notificationReceived function to

    notificationReceived: function(notification, payload, sender) { if (notification === 'Temperature' && sender.name === 'currentweather') { var currentweather = payload; if ( currentweather && currentweather.hasOwnProperty('temperature') ) { this.temp = currentweather.temperature; this.updateDom(); Log.log('The current temperature is ' + this.temp); } } },

    Check out the wiki for documentation, and of course keep asking questions here in these forums :)