Skip to content

Commit c0577ac

Browse files
Merge pull request #1 from Tom-Hirschberger/development
Development
2 parents dfb1837 + b4dfce3 commit c0577ac

File tree

2 files changed

+49
-23
lines changed

2 files changed

+49
-23
lines changed

MMM-Screen-Powersave-Notification.js

+48-23
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Module.register('MMM-Screen-Powersave-Notification', {
2121
displayHours: false,
2222
animationSpeed : 0,
2323
hideInsteadShutoff: false,
24+
changeToProfile : null,
2425
hideAnimationSpeed: 500,
2526
},
2627

@@ -54,31 +55,33 @@ Module.register('MMM-Screen-Powersave-Notification', {
5455
clearTimeout(this.currentDelayTimer)
5556

5657
const wrapper = document.createElement('div')
57-
const textWrapper = document.createElement('span')
58+
59+
if ((!this.delayDisabled) || (this.config.disabledText !== null)){
60+
const textWrapper = document.createElement('span')
5861
textWrapper.className = 'textWrapper'
5962

60-
textWrapper.innerHTML=this.config.countDownText
61-
wrapper.appendChild(textWrapper)
63+
textWrapper.innerHTML=this.config.countDownText
64+
wrapper.appendChild(textWrapper)
6265

6366

64-
const valueWrapper = document.createElement('span')
65-
valueWrapper.className = 'valueWrapper'
67+
const valueWrapper = document.createElement('span')
68+
valueWrapper.className = 'valueWrapper'
6669

67-
if(this.delayDisabled){
68-
valueWrapper.innerHTML = this.config.disabledText
69-
} else {
70-
//valueWrapper.innerHTML = moment("1900-01-01 00:00:00").add(this.currentDelay, 'seconds').format(this.config.countDownFormatString)
71-
valueWrapper.innerHTML = this.getTimeString(this.currentDelay)
72-
}
70+
if(this.delayDisabled){
71+
valueWrapper.innerHTML = this.config.disabledText
72+
} else {
73+
//valueWrapper.innerHTML = moment("1900-01-01 00:00:00").add(this.currentDelay, 'seconds').format(this.config.countDownFormatString)
74+
valueWrapper.innerHTML = this.getTimeString(this.currentDelay)
75+
}
7376

74-
wrapper.appendChild(valueWrapper)
77+
wrapper.appendChild(valueWrapper)
7578

76-
const self = this
77-
self.currentDelayTimer = setTimeout(function() {
78-
console.log("UPDATING currentDelay");
79-
self.currentDelay = self.currentDelay - (self.config.countDownUpdateInterval/1000);
80-
self.updateDom(self.config.animationSpeed)
81-
}, self.config.countDownUpdateInterval);
79+
const self = this
80+
self.currentDelayTimer = setTimeout(function() {
81+
self.currentDelay = self.currentDelay - (self.config.countDownUpdateInterval/1000);
82+
self.updateDom(self.config.animationSpeed)
83+
}, self.config.countDownUpdateInterval);
84+
}
8285

8386
return wrapper;
8487
},
@@ -89,13 +92,13 @@ Module.register('MMM-Screen-Powersave-Notification', {
8992
this.currentDelay = this.config.delay
9093
this.delayDisabled = false
9194
this.hiddenModules = null
95+
this.profileHistory = []
9296
},
9397

9498
hideModules: function(){
9599
const self = this
96100
self.hiddenModules = []
97101
var allModules = MM.getModules()
98-
self.sendNotification("DISABLE_PROFILE_TIMERS")
99102
allModules.enumerate(function(curModule){
100103
var callback = function(){}
101104
var options = {lockString: self.identifier}
@@ -106,7 +109,6 @@ Module.register('MMM-Screen-Powersave-Notification', {
106109

107110
showModules: function(){
108111
const self = this
109-
self.sendNotification("ENABLE_PROFILE_TIMERS")
110112
if(self.hiddenModules){
111113
for(var curModule in self.hiddenModules){
112114
var callback = function(){}
@@ -128,9 +130,22 @@ Module.register('MMM-Screen-Powersave-Notification', {
128130
}
129131
this.updateDom()
130132
} else if (notification === 'SCREEN_HIDE_MODULES'){
131-
self.hideModules()
133+
self.sendNotification("DISABLE_PROFILE_TIMERS")
134+
if (self.changeToProfile !== null){
135+
if(self.profileHistory[1] === self.config.changeToProfile){
136+
self.profileHistory[0] = self.profileHistory[1]
137+
}
138+
self.sendNotification("CURRENT_PROFILE", self.config.changeToProfile)
139+
} else {
140+
self.hideModules()
141+
}
132142
} else if (notification === 'SCREEN_SHOW_MODULES'){
133-
self.showModules()
143+
self.sendNotification("ENABLE_PROFILE_TIMERS")
144+
if (self.changeToProfile !== null){
145+
self.sendNotification("CURRENT_PROFILE", self.profileHistory[0])
146+
} else {
147+
self.showModules()
148+
}
134149
} else if (
135150
(notification === 'SCREENSAVE_ENABLED') ||
136151
(notification === 'SCREENSAVE_DISABLED')
@@ -140,15 +155,25 @@ Module.register('MMM-Screen-Powersave-Notification', {
140155
},
141156

142157
notificationReceived: function (notification, payload) {
158+
const self = this
143159
if (
144160
(notification === 'USER_PRESENCE') ||
145-
(notification === 'CHANGED_PROFILE') ||
146161
(notification === 'SCREEN_TOGGLE') ||
147162
(notification === 'SCREEN_ON') ||
148163
(notification === 'SCREEN_OFF') ||
149164
(notification === 'SCREEN_POWERSAVE')
150165
) {
151166
this.sendSocketNotification(notification, payload)
152167
}
168+
else if (notification === 'CHANGED_PROFILE'){
169+
if (self.profileHistory.length > 1){
170+
self.profileHistory[0] = self.profileHistory[1]
171+
self.profileHistory[1] = payload.to
172+
} else {
173+
self.profileHistory[0] = payload.to
174+
self.profileHistory[1] = payload.to
175+
}
176+
this.sendSocketNotification(notification, payload)
177+
}
153178
}
154179
})

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ To display the module insert it in the config.js file. Here is an example:
4545
| animationSpeed | If you like the update of the counter to be animated you can specify an interval with this value | Integer | 0 |
4646
| hideInsteadShutoff | If you use an display that can not be turned off and on with the pi you can hide the modules only instead. Turning this option to true will do so | boolean | false |
4747
| hideAnimationSpeed | The hiding and reappearing off the modules will be animated with this speed | Integer | 500 |
48+
| changeToProfile | If the hiding is enabled and this string is set an change to the new profile is triggered. If the screensave mode is disabled a change to the previous profile will be initiated | String | null |
4849

4950
## Received Notifications
5051
| Notification | Payload | Default | Result |

0 commit comments

Comments
 (0)