Skip to content

Commit

Permalink
an counter can be displayed now if a position for the module is speci…
Browse files Browse the repository at this point in the history
…fied
  • Loading branch information
Tom-Hirschberger committed Apr 6, 2020
1 parent 1555ed7 commit 3eb2345
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 4 deletions.
81 changes: 80 additions & 1 deletion MMM-Screen-Powersave-Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,91 @@ Module.register('MMM-Screen-Powersave-Notification', {
screenOnCommand: '/usr/bin/vcgencmd display_power 1',
screenOffCommand: '/usr/bin/vcgencmd display_power 0',
screenStatusCommand: '/usr/bin/vcgencmd display_power',
turnScreenOnIfProfileDelayIsSet: true
turnScreenOnIfProfileDelayIsSet: true,
countDownText: 'Display powersave: ',
disabledText: 'disabled',
countDownUpdateInterval: 5000,
displayHours: false,
animationSpeed : 0
},

getStyles: function() {
return ['screen-powersave.css']
},

getScripts: function() {
return ['moment.js']
},

getTimeString: function(seconds) {
var remainingSeconds = seconds
if(this.config.displayHours){
remainingSeconds = seconds % 3600
hours = Math.round((seconds - remainingSeconds)/ 3600)
}

remainingSeconds2 = remainingSeconds % 60
var minutes = Math.round((remainingSeconds - remainingSeconds2) / 60)


if(this.config.displayHours){
return (""+hours).padStart(2,'0')+":"+(""+minutes).padStart(2,'0')+":"+(""+remainingSeconds2).padStart(2,'0')
} else {
return (""+minutes).padStart(2,'0')+":"+(""+remainingSeconds2).padStart(2,'0')
}
},

getDom: function() {
clearTimeout(this.currentDelayTimer)

const wrapper = document.createElement('div')
const textWrapper = document.createElement('span')
textWrapper.className = 'textWrapper'

textWrapper.innerHTML=this.config.countDownText
wrapper.appendChild(textWrapper)


const valueWrapper = document.createElement('span')
valueWrapper.className = 'valueWrapper'

if(this.delayDisabled){
valueWrapper.innerHTML = this.config.disabledText
} else {
//valueWrapper.innerHTML = moment("1900-01-01 00:00:00").add(this.currentDelay, 'seconds').format(this.config.countDownFormatString)
valueWrapper.innerHTML = this.getTimeString(this.currentDelay)
}

wrapper.appendChild(valueWrapper)

const self = this
self.currentDelayTimer = setTimeout(function() {
console.log("UPDATING currentDelay");
self.currentDelay = self.currentDelay - (self.config.countDownUpdateInterval/1000);
self.updateDom(self.config.animationSpeed)
}, self.config.countDownUpdateInterval);

return wrapper;
},

start: function () {
Log.info("Starting module: " + this.name);
this.sendSocketNotification('CONFIG', this.config)
this.currentDelay = this.config.delay
this.delayDisabled = false
},

socketNotificationReceived: function (notification, payload) {
const self = this
if( notification === 'SCREEN_TIMEOUT_CHANGED'){
this.currentDelay = payload.delay
if(payload.delay === 0){
this.delayDisabled = true
} else {
this.delayDisabled = false
}
this.updateDom()
}
},

notificationReceived: function (notification, payload) {
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ To display the module insert it in the config.js file. Here is an example:
| screenOnCommand | the command which is used to turn the screen on | String | '/usr/bin/vcgencmd display_power 1' |
| screenOffCommand | the command which is used to turn the screen off | String | '/usr/bin/vcgencmd display_power 0' |
| 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' |
| 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
| 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 |
| 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: ' |
| disabledText | If the display powersave is disabled an message instead of the counter will be display | String | 'disabled' |
| displayHours | If you use such long powersave intervals that you need hours you can set this value to true | boolean | false |
| countDownUpdateInterval | How often should the counter be updated | Integer | 5000 |
| animationSpeed | If you like the update of the counter to be animated you can specify an interval with this value | Integer | 0 |

## Notifications
| Notification | Payload | Default | Result |
Expand Down
2 changes: 1 addition & 1 deletion node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ module.exports = NodeHelper.create({
self.currentProfile = payload.to
self.currentProfilePattern = new RegExp('\\b'+payload.to+'\\b')

if(self.config.profiles){
if(self.config.profiles && (Object.keys(self.config.profiles).length > 0)){
self.clearAndSetScreenTimeout(true, profileChange=true);
}
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "",
"main": "MMM-Screen-Powersave-Notification.js",
"dependencies": {
"child_process": "latest"
"child_process": "latest",
"moment": "latest"
},
"devDependencies": {},
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions screen-powersave.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.MMM-Screen-Powersave-Notification {
font-size: 14px;
}

0 comments on commit 3eb2345

Please sign in to comment.