Closed Galapgs closed 3 years ago
pushover(payload) {
return new Promise((resolve, reject) => {
try {
if (typeof payload == 'string')
payload = {message: payload, priority: 0};
if (!this.config.pushover)
throw new Error('You must configure Pushover credentials.');
if (!this.config.pushover.user)
throw new Error('You must configure Pushover user.');
if (!this.config.pushover.token)
throw new Error('You must configure Pushover token.');
var push = new Pushover(this.config.pushover);
this.log('Sending message:', message);
push.send(payload, (error, result) => {
if (error) reject(error);
else resolve();
});
} catch (error) {
reject(error);
}
});
}
This would work and be backwards compatible?
// Translate priority strings to Pushover priority values
if (typeof priority == 'string') {
var priorities = {
'lowest':-2,
'low': -1,
'normal': 0,
'high': 1,
'emergency': 2
};
priority = priorities[priority];
}
if (typeof priority != 'number')
priority = 0;
Also added this so the pushprio is not needed.
Published a new version 1.0.12 on npm. Works great with titles. Your code was an inspiration! Does it work for you? Here is a small bit of my config.
{
"platform": "Pushover",
"name": "Pushover",
"pushover": {
"user": "xxx",
"token": "xxx"
},
"messages": [
{
"name": "Larm på",
"title": "Larm",
"message": "Aktiverat",
"priority": "high"
},
{
"name": "Larm av",
"title": "Larm",
"message": "Avaktiverat",
"priority": "high"
},
{
"name": "Bilen låst",
"title": "Bilen",
"message": "Låst"
},
{
"name": "Bilen upplåst",
"title": "Bilen",
"message": "Upplåst"
},
{
"name": "Ringklocka",
"message": "Det ringer på dörren",
"priority": "high"
}
]
}
Only messages with the priority "high" or "emergency" are sent when the master switch is off.
Just noticed - the {"priority":"emergency"} requires some more work... But seems to work in 1.0.14.
Looks great and it's working, thank you!
Thank you for your input. It was a mistake by just setting priority to zero when calling Pushover.send() - didn't know this module would be used so much. I will review my code, read up on the Pushover documentation and do better.