-
Notifications
You must be signed in to change notification settings - Fork 3
/
lib.js
54 lines (47 loc) · 1.91 KB
/
lib.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
"use strict";
function RoonApiSourceSelection(roon, opts) {
this._objs = {};
this._svc = roon.register_service("com.roonlabs.sourcecontrol:1", {
subscriptions: [
{
subscribe_name: "subscribe_controls",
unsubscribe_name: "unsubscribe_controls",
start: (req) => {
req.send_continue("Subscribed", { controls: Object.values(this._objs).reduce((p,e) => p.push(e.state) && p, []) });
}
}
],
methods: {
get_all: (req) => {
req.send_complete("Success", { controls: Object.values(this._objs).reduce((p,e) => p.push(e.state) && p, []) });
},
standby: (req) => {
var d = this._objs[req.body.control_key];
d.standby(req);
},
convenience_switch: (req) => {
var d = this._objs[req.body.control_key];
d.convenience_switch(req);
}
}
});
this.services = [ this._svc ];
}
RoonApiSourceSelection.prototype.new_device = function(o) {
o.state.control_key = o.state.control_key || "1";
if (this._objs[o.state.control_key])
throw new Error('Must set control key to unique id');
this._objs[o.state.control_key] = o;
this._svc.send_continue_all('subscribe_controls', "Changed", { controls_added: [ o.state ] });
return {
destroy: () => {
this._svc.send_continue_all('subscribe_controls', "Changed", { controls_removed: [ o.state.control_key ] });
delete(this._objs[o.state.control_key]);
},
update_state: (state) => {
for (let x in state) if (o.state[x] !== state[x]) o.state[x] = state[x];
this._svc.send_continue_all('subscribe_controls', "Changed", { controls_changed: [ o.state ] });
}
};
};
exports = module.exports = RoonApiSourceSelection;