Read the statement by Michael Teeuw here.
Not updating at midnight...
-
@BKeyport logging
There are two logs
Node_helper goes to npm start console
Modulename.js goes to the browser logThere are a couple modules that will send the browser log records to the console
MMM-Logging, mmrize has an updated version, so do I.I don’t know why it worked before, or why it’s not working now.
We added some checking for valid position names, instead of crashing
We added async to some mm functions, but
Timeout and interval are js functions.Only way to debug the browser side is to use the developer window debugger (sources tab)
-
@BKeyport I’d be interested in the functions that you are having trouble with, as there are very few.
-
I think I got it figured out - Based on research elsewhere - if I’m correct:
start: function()
is only called upon load, correct?ASSUMING that’s the case, this seems to work better:
start: function () { function scheduleMidnightUpdate() { const now = new Date(); const nextMidnight = new Date(now); // Set the time to midnight nextMidnight.setHours(24, 0, 0, 0); // Calculate the time remaining until the next midnight const timeUntilMidnight = nextMidnight - now; // Schedule the updateDom method to be called at midnight setTimeout(() => { this.updateDom(); // Reschedule the update for the next midnight scheduleMidnightUpdate.call(this); }, timeUntilMidnight); } // Call the function to start the first schedule scheduleMidnightUpdate.call(this); },
Now, This seems to work on testing - but it will fail in testing if I change the clock after starting MM.
Is there anyway y’all can see to improve this, or am I good?
-
@BKeyport
Your DOM might not be rendered yet on “start” imo. I think manipulating DOM after “DOM_OBJECT_CREATED” notification would be safer. -
Yes the documented flow is, as I recall on my phone,
Init
Getstyles
Getscripts
GetTemplates
Start
Notification received
AllModulesStarted
DOMobjectsCreated
getDOM -
-
@BKeyport after the notification
From the doc
DOM_OBJECTS_CREATED - All dom objects are created. The system is now ready to perform visual changes.
-
@sdetweil said in Not updating at midnight...:
DOM_OBJECTS_CREATED - All dom objects are created. The system is now ready to perform visual changes
start: function () { function scheduleMidnightUpdate() { const now = new Date(); const nextMidnight = new Date(now); // Set the time to midnight nextMidnight.setHours(24, 0, 0, 0); // Calculate the time remaining until the next midnight const timeUntilMidnight = nextMidnight - now; // Schedule the updateDom method to be called at midnight setTimeout(() => { this.updateDom(); // Reschedule the update for the next midnight scheduleMidnightUpdate.call(this); }, timeUntilMidnight); } }, notificationReceived: function (notification, payload, sender) { if (notification === 'CALENDAR_EVENTS') { this.storedEvents = JSON.parse(JSON.stringify(payload)) this.updateDom(); } else if (notification === 'DOM_OBJECTS_CREATED') { // Call the function to start the first schedule scheduleMidnightUpdate.call(this); }
This is the only source I see in the docs of that - a notification. Is that correct?
Thanks for the patience after the double misunderstanding.
-
https://docs.magicmirror.builders/development/core-module-file.html
you could have done all the initial event calculating in one function
used interval for the midnights (as it’s a fixed number)
-
@BKeyport MODULE_DOM_CREATED means YOUR getDom()/getTemplateData() has been called