Read the statement by Michael Teeuw here.
Connecting Modules to Each Other
-
@tonkxy
Hmmmm… I cannot understand thesetCurrentWeatherType
.Anyway, I recommend you this module; https://github.com/BrianHepler/MMM-WeatherBackground
You need to study how MM module works, at least to train how to use.You don’t need to pull weather info from an external weather API like Darksky. Already there are many modules showing weather info on MM screen and spitting that info out through
notification
.For example, default
weather
module also emit notifications of weather info periodically. All you need to do is catching that notification and consume them in your module.default
weather
module would emitCURRENTWEATHER_TYPE
notification.
You can catch that notification like this.notificationReceived: function (notification, payload, sender) { if (notification === 'CURRENTWEATHER_TYPE') { console.log(payload) // manipulate payload then extract data what you need. // do your job } }
Anyway, Study the above module. That has almost all features you are trying. (except the image source)
-
@sdetweil great callout! I did not know I could debug. I do get a type back. I did the break trick on where its in an if statement and the type is still undefined in setImage
-
@tonkxy well
setImage: function () { let rand = Math.floor(Math.random() * 4)+1; //randomn number to pick gif var day = new Date(); var hour = day.getHours(); var type = this.currentWeatherTemperature; // < ----
notification
//From data currentweather set weather type setCurrentWeatherType: function(type){ this.currentWeatherType = type; // < ---- }, notificationReceived: function (notification, payload, sender) { if (notification === 'DOM_OBJECTS_CREATED') { this.job() } //weather dom if(notification === "CURRENTWEATHER_TYPE"){ this.setCurrentWeatherType(payload.type); } },
this.currentWeatherTemperature is NOT this.currentWeatherType
-
@sdetweil that definitely was part of it.
I am able to successfully see the payload in notifications. Just working a way to retain it and be able to use in setImage. Thank you!
-
@tonkxy should be able to save the payload pointer and then use that day later. I do it all the time
this.weatherInfo = payload
for example
remember your module could get called at getDom() long before the other module sends the notification, so u need to check if it has arrived yet.
-
@sdetweil funny you say that. Ive been reading and you offered the solution on someone using compliments + weather. My issue is when i step through to set image, the type is back to undefined and not carried from the notification. Im wondering if its in my order as to why its going back to undefined
-
@tonkxy I would put a stop everywhere u set it.
make sure the this. pointer is pointing to the same place set vs use
-
@sdetweil when you say stop you mean in my debug to see where im losing the value?
-
@tonkxy correct
-
@sdetweil Great advice.
I stepped through and you were right on two things. When it starts, it defaults with the else case, because it hasn’t fetched the type yet. Once it does fetch the type I was resetting it in the myJob() function causing it to be undefined again.
I appreciate the break down on this. JS is definitely giving me a run for my money on learning it.