-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
executable file
·98 lines (77 loc) · 2.52 KB
/
index.ts
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
92
93
94
95
96
97
98
// DOMUSTO
import config from '../../config';
import DomustoPlugin from '../../domusto/DomustoPlugin';
// INTERFACES
import { Domusto } from '../../domusto/DomustoTypes';
// PLUGIN SPECIFIC
import * as PushBullet from 'pushbullet';
/**
* Shell plugin for DOMUSTO
* @author Bas van Dijk
* @version 0.0.1
*
* @class DomustoPushBullet
* @extends {DomustoPlugin}
*/
class DomustoPushBullet extends DomustoPlugin {
private pushBulletInstances = [];
/**
* Creates an instance of DomustoPushBullet.
* @param {any} Plugin configuration as defined in the config.js file
* @memberof DomustoPushBullet
*/
constructor(pluginConfiguration: Domusto.PluginConfiguration) {
super({
plugin: 'Pushbullet executer',
author: 'Bas van Dijk',
category: Domusto.PluginCategories.push,
version: '0.0.1',
website: 'http://domusto.com'
});
this.pluginConfiguration = pluginConfiguration;
const isConfigurationValid = this.validateConfigurationAttributes(pluginConfiguration.settings, [
{
attribute: 'accessTokens',
type: 'object'
}
]);
if (isConfigurationValid) {
// Create a new PushBullet instance for each access token
pluginConfiguration.settings.accessTokens.forEach(token => {
this.pushBulletInstances.push(new PushBullet(token));
});
this.console.header(`${pluginConfiguration.id} plugin ready for sending / receiving data`);
}
}
/**
* Executed when a signal is received for this plugin
*
* @param {Domusto.Signal} signal
* @memberof DomustoShell
*/
onSignalReceivedForPlugin(signal: Domusto.Signal) {
switch (signal.deviceId) {
case 'note':
this.sendNoteToAll(signal.data['title'], signal.data['message']);
break;
case 'link':
case 'file':
default:
this.console.error('No Pushbullet action defined for ', signal.deviceId);
break;
}
}
/**
* Push message to all subscribed api keys
*
* @param {string} title Message title
* @param {string} message Message content
* @memberof DomustoPushBullet
*/
sendNoteToAll(title: string, message: string) {
this.pushBulletInstances.forEach(instance => {
instance.note('', title, message);
});
}
}
export default DomustoPushBullet;