Skip to content

Commit 3eb2345

Browse files
an counter can be displayed now if a position for the module is specified
1 parent 1555ed7 commit 3eb2345

5 files changed

+92
-4
lines changed

MMM-Screen-Powersave-Notification.js

+80-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,91 @@ Module.register('MMM-Screen-Powersave-Notification', {
1414
screenOnCommand: '/usr/bin/vcgencmd display_power 1',
1515
screenOffCommand: '/usr/bin/vcgencmd display_power 0',
1616
screenStatusCommand: '/usr/bin/vcgencmd display_power',
17-
turnScreenOnIfProfileDelayIsSet: true
17+
turnScreenOnIfProfileDelayIsSet: true,
18+
countDownText: 'Display powersave: ',
19+
disabledText: 'disabled',
20+
countDownUpdateInterval: 5000,
21+
displayHours: false,
22+
animationSpeed : 0
23+
},
24+
25+
getStyles: function() {
26+
return ['screen-powersave.css']
27+
},
28+
29+
getScripts: function() {
30+
return ['moment.js']
31+
},
32+
33+
getTimeString: function(seconds) {
34+
var remainingSeconds = seconds
35+
if(this.config.displayHours){
36+
remainingSeconds = seconds % 3600
37+
hours = Math.round((seconds - remainingSeconds)/ 3600)
38+
}
39+
40+
remainingSeconds2 = remainingSeconds % 60
41+
var minutes = Math.round((remainingSeconds - remainingSeconds2) / 60)
42+
43+
44+
if(this.config.displayHours){
45+
return (""+hours).padStart(2,'0')+":"+(""+minutes).padStart(2,'0')+":"+(""+remainingSeconds2).padStart(2,'0')
46+
} else {
47+
return (""+minutes).padStart(2,'0')+":"+(""+remainingSeconds2).padStart(2,'0')
48+
}
49+
},
50+
51+
getDom: function() {
52+
clearTimeout(this.currentDelayTimer)
53+
54+
const wrapper = document.createElement('div')
55+
const textWrapper = document.createElement('span')
56+
textWrapper.className = 'textWrapper'
57+
58+
textWrapper.innerHTML=this.config.countDownText
59+
wrapper.appendChild(textWrapper)
60+
61+
62+
const valueWrapper = document.createElement('span')
63+
valueWrapper.className = 'valueWrapper'
64+
65+
if(this.delayDisabled){
66+
valueWrapper.innerHTML = this.config.disabledText
67+
} else {
68+
//valueWrapper.innerHTML = moment("1900-01-01 00:00:00").add(this.currentDelay, 'seconds').format(this.config.countDownFormatString)
69+
valueWrapper.innerHTML = this.getTimeString(this.currentDelay)
70+
}
71+
72+
wrapper.appendChild(valueWrapper)
73+
74+
const self = this
75+
self.currentDelayTimer = setTimeout(function() {
76+
console.log("UPDATING currentDelay");
77+
self.currentDelay = self.currentDelay - (self.config.countDownUpdateInterval/1000);
78+
self.updateDom(self.config.animationSpeed)
79+
}, self.config.countDownUpdateInterval);
80+
81+
return wrapper;
1882
},
1983

2084
start: function () {
2185
Log.info("Starting module: " + this.name);
2286
this.sendSocketNotification('CONFIG', this.config)
87+
this.currentDelay = this.config.delay
88+
this.delayDisabled = false
89+
},
90+
91+
socketNotificationReceived: function (notification, payload) {
92+
const self = this
93+
if( notification === 'SCREEN_TIMEOUT_CHANGED'){
94+
this.currentDelay = payload.delay
95+
if(payload.delay === 0){
96+
this.delayDisabled = true
97+
} else {
98+
this.delayDisabled = false
99+
}
100+
this.updateDom()
101+
}
23102
},
24103

25104
notificationReceived: function (notification, payload) {

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ To display the module insert it in the config.js file. Here is an example:
3535
| screenOnCommand | the command which is used to turn the screen on | String | '/usr/bin/vcgencmd display_power 1' |
3636
| screenOffCommand | the command which is used to turn the screen off | String | '/usr/bin/vcgencmd display_power 0' |
3737
| screenStatusCommand | the command which is used to check if the screen is on (result needs to be 'display_power 1' if on) | String | '/usr/bin/vcgencmd display_power' |
38-
| turnScreenOnIfProfileDelayIsSet | if you do not want the screen to be turned on if the profile changes and a profile specific delay is set set this value to false | boolean | true
38+
| turnScreenOnIfProfileDelayIsSet | if you do not want the screen to be turned on if the profile changes and a profile specific delay is set set this value to false | boolean | true |
39+
| countDownText | If you specify a position for the module in the config an countdown will be displayed; the countdown starts with an text that you can change with this value | String | 'Display powersave: ' |
40+
| disabledText | If the display powersave is disabled an message instead of the counter will be display | String | 'disabled' |
41+
| displayHours | If you use such long powersave intervals that you need hours you can set this value to true | boolean | false |
42+
| countDownUpdateInterval | How often should the counter be updated | Integer | 5000 |
43+
| animationSpeed | If you like the update of the counter to be animated you can specify an interval with this value | Integer | 0 |
3944

4045
## Notifications
4146
| Notification | Payload | Default | Result |

node_helper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ module.exports = NodeHelper.create({
173173
self.currentProfile = payload.to
174174
self.currentProfilePattern = new RegExp('\\b'+payload.to+'\\b')
175175

176-
if(self.config.profiles){
176+
if(self.config.profiles && (Object.keys(self.config.profiles).length > 0)){
177177
self.clearAndSetScreenTimeout(true, profileChange=true);
178178
}
179179
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "",
55
"main": "MMM-Screen-Powersave-Notification.js",
66
"dependencies": {
7-
"child_process": "latest"
7+
"child_process": "latest",
8+
"moment": "latest"
89
},
910
"devDependencies": {},
1011
"scripts": {

screen-powersave.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.MMM-Screen-Powersave-Notification {
2+
font-size: 14px;
3+
}

0 commit comments

Comments
 (0)