-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
121 lines (116 loc) · 2.85 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import {Plugin} from 'lisa-plugin';
import {createRequire} from 'module';
import config from './config/index.js';
import drivers from './drivers/index.js';
const require = createRequire(import.meta.url);
const pkg = require('./package.json');
export default class SoundTouchPlugin extends Plugin {
/**
* Called when
* @param action to execute
* @param infos context of the action
* @return Promise
*/
interact(action, infos) {
const room = infos.fields.room || infos.context.room
const device = infos.fields.device
if (device && device.pluginName !== this.fullName) {
return Promise.resolve()
}
const number = infos.fields.number
let key
let value
switch (action) {
case 'SET_CHANNEL':
key = 'preset'
value = infos.fields.channel
break
case 'SET_SOURCE':
key = 'source'
value = infos.fields.source
if (infos.fields.index) {
value += '_' + infos.fields.index
}
break
case 'DEVICE_TURN_ON':
key = 'powered'
value = true
break
case 'DEVICE_TURN_OFF':
key = 'powered'
value = false
break
case 'MUTE_VOLUME':
break
case 'UNMUTE_VOLUME':
break
case 'SET_VOLUME':
key = 'volume'
value = number
break
case 'INCREASE_VOLUME_AGAIN':
case 'INCREASE_VOLUME':
key = 'increase_volume'
value = number
break
case 'DECREASE_VOLUME_AGAIN':
case 'DECREASE_VOLUME':
key = 'decrease_volume'
value = number
break
case 'PAUSE_MEDIA_CENTER':
key = 'playpause'
value = 'pause'
break
case 'PLAY_MEDIA_CENTER':
key = 'playpause'
value = 'play'
break
case 'STOP_MEDIA_CENTER':
key = 'stop'
break
case 'NEXT_SONG':
case 'NEXT_SONG_AGAIN':
key = 'next'
break
case 'PREVIOUS_SONG':
case 'PREVIOUS_SONG_AGAIN':
key = 'previous'
break
default:
return Promise.resolve()
}
const criteria = {}
if (room) {
criteria.roomId = room.id || room
return this.lisa.findDevices(criteria).then((devices) => {
const data = {
lifestyle: [],
soundtouch: [],
}
for (let i = 0; i < devices.length; i++) {
const deviceBose = devices[i]
data[deviceBose.driver].push(deviceBose)
}
return Promise.all([
this.drivers['soundtouch'].setDevicesValue(data.soundtouch, key, value),
this.drivers['lifestyle'].setDevicesValue(data.lifestyle, key, value),
])
})
}
else if (device) {
return this.drivers[device.driver].setDeviceValue(device, key, value)
}
else {
return Promise.resolve()
}
}
constructor(app) {
super(app, {
config: config,
drivers: drivers,
pkg: pkg,
// bots: require('./bots')
})
}
}