-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathapp.js
99 lines (90 loc) · 3.45 KB
/
app.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
"use strict";
module.exports.init = function () {
Homey.manager('flow').on('action.play', function (callback, args) {
Homey.manager('drivers').getDriver('squeezebox').capabilities.play.set(
args.device,
true,
function (err, success) {
// Notify Homey of success of failure, respectively.
if (typeof callback == 'function') {
callback(null, !err && success);
};
}
);
});
Homey.manager('flow').on('action.pause', function (callback, args) {
Homey.manager('drivers').getDriver('squeezebox').capabilities.pause.set(
args.device,
true,
function (err, success) {
// Notify Homey of success of failure, respectively.
if (typeof callback == 'function') {
callback(null, !err && success);
};
}
);
});
Homey.manager('flow').on('action.volume', function (callback, args) {
Homey.manager('drivers').getDriver('squeezebox').capabilities.volume.set(
args.device,
args.volume,
function (err, success) {
// Notify Homey of success of failure, respectively.
if (typeof callback == 'function') {
callback(null, !err && success);
};
}
);
});
Homey.manager('flow').on('action.playPlaylist', function (callback, args) {
var SqueezeServer = require('squeezenode');
var mySqueezeServer = new SqueezeServer(
Homey.manager('settings').get('serverAddress'),
Homey.manager('settings').get('serverPort')
);
mySqueezeServer.on('register', function () {
mySqueezeServer.request(
args.device.id,
["playlistcontrol", "cmd:load", "playlist_id:" + args.playlist.id],
function (reply) {
// TODO: Detect failures.
if (typeof callback == 'function') {
callback(null, true);
}
}
);
});
});
Homey.manager('flow').on('action.playPlaylist.playlist.autocomplete', function (callback, data) {
var SqueezeServer = require('squeezenode');
var mySqueezeServer = new SqueezeServer(
Homey.manager('settings').get('serverAddress'),
Homey.manager('settings').get('serverPort')
);
mySqueezeServer.on('register', function () {
var searchParams = ["playlists", 0, 10];
if (data.query != '') {
searchParams.push('search:' + data.query);
}
mySqueezeServer.request(
data.args.device.id,
searchParams,
function (reply) {
var playlists = [];
if (reply.result.count > 0) {
playlists = reply.result.playlists_loop.map(function (item) {
return {
id: item.id,
name: item.playlist
};
});
}
// TODO: Detect failures.
if (typeof callback == 'function') {
callback(null, playlists);
}
}
);
});
});
};