-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
91 lines (78 loc) · 3.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*** Z-Wave-Me-pushsafer Z-Way HA module *******************************************
Version: 1.0.5
(c) 2023 Appzer.de
-----------------------------------------------------------------------------
Author: Kevin Siml
Description: Send Push Notification by Pushsaver.com Service
******************************************************************************/
// ----------------------------------------------------------------------------
// --- Class definition, inheritance and setup
// ----------------------------------------------------------------------------
function NotificationPushsafer (id, controller) {
// Call superconstructor first (AutomationModule)
NotificationPushsafer.super_.call(this, id, controller);
}
inherits(NotificationPushsafer, AutomationModule);
_module = NotificationPushsafer;
// ----------------------------------------------------------------------------
// --- Module instance initialized
// ----------------------------------------------------------------------------
NotificationPushsafer.prototype.init = function (config) {
NotificationPushsafer.super_.prototype.init.call(this, config);
var self = this;
this.vDev = this.controller.devices.create({
deviceId: "NotificationPushsafer_" + this.id,
defaults: {
deviceType: "toggleButton",
//deviceType: "switchBinary",
// in case you want to use if<>then you may want to switch devicetype "switchBinary" to handle events
metrics: {
level: 'on', // it is always on, but usefull to allow bind
icon: '',
title: 'NotificationPushsafer ' + this.id
}
},
overlay: {},
handler: function () {
// If Private Keys and Message for Pushsafer exist, then send message
if (self.config.private_key_token && self.config.message) {
http.request({
method: 'POST',
url: "https://www.pushsafer.com/api",
data: {
k: self.config.private_key_token,
m: self.config.message,
t: self.config.message_title,
d: self.config.device,
i: self.config.icon,
c: self.config.iconcolor,
s: self.config.sound,
v: self.config.vibration,
u: self.config.url,
ut: self.config.urltitle,
l: self.config.time2live,
pr: self.config.priority,
re: self.config.retry,
ex: self.config.expire,
cr: self.config.confirm,
a: self.config.answer,
ao: self.config.answeroptions,
af: self.config.answerforce
}
});
}
self.vDev.set("metrics:level", "on"); // update on ourself to allow catch this event
},
moduleId: this.id
});
};
NotificationPushsafer.prototype.stop = function () {
if (this.vDev) {
this.controller.devices.remove(this.vDev.id);
this.vDev = null;
}
NotificationPushsafer.super_.prototype.stop.call(this);
};
// ----------------------------------------------------------------------------
// --- Module methods
// ----------------------------------------------------------------------------