-
Notifications
You must be signed in to change notification settings - Fork 5
/
MMM-Porcupine.js
74 lines (69 loc) · 2.1 KB
/
MMM-Porcupine.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
// Module : MMM-Porcupine
Module.register("MMM-Porcupine", {
defaults: {
debug: false,
// Default hotword is 'porcupine'
hotword: "porcupine",
sensitivity: 0.7,
onDetected: {
notification: "ASSISTANT_ACTIVATE",
parameters: {
type: "MIC",
profile: "default",
chime: true
}
}
},
start: function() {
this.config = this.configAssignment({}, this.defaults, this.config)
this.sendSocketNotification('INIT', this.config)
},
notificationReceived: function(notification, payload, sender) {
switch (notification) {
case "ASSISTANT_READY":
case "A2D_AMK2_READY":
case "PORCUPINE_START":
this.sendSocketNotification('START')
break
case "A2D_AMK2_BUSY":
case "PORCUPINE_STOP":
this.sendSocketNotification('STOP')
break
}
},
// When node_helper sends the DETECTED socket notification and it is recieved
// here
socketNotificationReceived: function(notification, payload) {
switch (notification) {
case "DETECTED":
// Send ASSISTANT_ACTIVATE notification to MM Google Assistant MK2
// find handling code in line 278 of MMM-AssistantMk2.js
// https://github.com/bugsounet/MMM-AssistantMk2
this.sendNotification(this.config.onDetected.notification, this.config.onDetected.parameters)
break
}
},
// Assign the configuration
configAssignment : function (result) {
var stack = Array.prototype.slice.call(arguments, 1)
var item
var key
while (stack.length) {
item = stack.shift()
for (key in item) {
if (item.hasOwnProperty(key)) {
if (typeof result[key] === "object" && result[key] && Object.prototype.toString.call(result[key]) !== "[object Array]") {
if (typeof item[key] === "object" && item[key] !== null) {
result[key] = this.configAssignment({}, result[key], item[key])
} else {
result[key] = item[key]
}
} else {
result[key] = item[key]
}
}
}
}
return result
},
})