Read the statement by Michael Teeuw here.
Auto-disable module
-
Could you point me in the right direction as to how I could hide a complete module with a .hide() call?
-
First send a notification from your main module.js to node_helper.js to ask it to look for the time of day.
Something like in your main module.js:start: function(){ this.sendSocketNotification('LookForTime'); }
In your node_helper.js, you could check for the time. Once you see that it is night, you can send a socket notification to your main module.js file like:
socketNotificationReceived: function(notification, payload){ if(notification === 'LookForTime'){ // Keep checking for time. Once night, if(night){ this.sendSocketNotification('NIGHT'); } } }
In your main module.js:
socketNotificationReceived: function(notification, payload){ if(notification === 'NIGHT'){ this.hide(); } }
-
@ronny3050 Impressive response, thank you!
-
@yo-less No problem! If you have any issues, I’ll be glad to answer them on chat :)
-
No need to use node helper for that. All modules can use
'moment.js'
as it’s already in the code (for the time display, calendar, and various timers.) So write your code in the main module’sjs
file.moment.now() gives you the current time.
Take a gander at my calendar_monthly module where I keep track of time for the refreshes. The calendar DOM only refreshes once a day, at midnight. However, because browsers tend to get “stuck” every so often during the day, I also keep track of the hours. What that means is, there is a “heartbeat” every hour to stay accurate to the actual time. If the browser got stuck and the clock delayed by a few seconds, the heartbeat will fix that every 60 minutes. Then, only when it reaches midnight, will it actually reload the DOM.
In the code, look at the
'start'
function where I set the time till nextmidnight
. Then I fire off ascheduleUpdate()
which sets a delay to the nexthour
. When that timer expires, a couple of things happen:- it checks whether the current time is past the
midnight
set earlier. If so,
- it will reload the DOM (which refreshes the calendar display),
- it will calculate the next
midnight
- it will reset the timer to the next
hour
- it will loop back to
scheduleUpdate()
OR
- if the current time is LESS than
midnight
,
- it will reset the timer to the next
hour
- it will loop back to
scheduleUpdate()
… and the DOM never gets touched.
This way I don’t reload the calendar unnecessarily throughout the day. It only happens once, but the timer fires off every hour, just to keep track of time. If I didn’t do that, at least on my rpi, I noticed the browser’s time will drift by several minutes in a 24 hour period.
- it checks whether the current time is past the
-
@KirAsh4’s solution is much neater and elegant. He never ceases to amaze me! :D
-
@KirAsh4 - It’s amazing for me to see how helpful and how full of good advice people on this forum are. Thank your for that!
I’ve got my module up and running now and will go through troubleshooting it. As soon as I feel that it’s working as it should, I will try to implement the feature to automatically disable it if necessary, I will study your code then as well. Thanks for pointing me in a good direction!
-
This post is deleted!