Skip to content
This repository has been archived by the owner on Mar 6, 2022. It is now read-only.

Suspend/resume modules on absence/presence #83

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
22 changes: 21 additions & 1 deletion MMM-PIR-Sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Module.register('MMM-PIR-Sensor',{
powerSaving: true,
powerSavingDelay: 0,
powerSavingNotification: false,
powerSavingMessage: "Monitor will be turn Off by PIR module",
powerSavingMessage: "Monitor will be turn Off by PIR module",
suspendResume: true
},

// Override socket notification handler.
Expand All @@ -31,6 +32,25 @@ Module.register('MMM-PIR-Sensor',{
if (payload === false && this.config.powerSavingNotification === true){
this.sendNotification("SHOW_ALERT",{type:"notification", message:this.config.powerSavingMessage});
}

if(this.config.suspendResume) {
self = this;

// Suspend all modules
MM.getModules().enumerate((module) => {
if(!module.hidden) {
if(payload) { // User present
clearTimeout(self.suspendTimeout);
module.resume();
} else { // User not present
setTimeout(function() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why set a separate timeout? Would it not be better to use the timeout defined in note_helper.js for reactivation, instead?

console.log(module);
module.suspend();
}, self.config.powerSavingDelay * 1000);
}
}
});
}
} else if (notification === 'SHOW_ALERT') {
this.sendNotification(notification, payload)
}
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ The following properties can be configured:
<br><b>Default value:</b> <code>"Monitor will be turn Off by PIR module"</code>
</td>
</tr>
<tr>
<td><code>suspendResume</code></td>
<td>Suspend and resume all visible modules on user absence/presence.<br>
<br><b>Possible values:</b> <code>boolean</code>
<br><b>Default value:</b> <code>true</code>
</td>
</tr>
</tbody>
</table>

Expand Down
Loading