forked from JimJamUrCode/lirc_node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlirc_node.js
More file actions
49 lines (40 loc) · 1.35 KB
/
lirc_node.js
File metadata and controls
49 lines (40 loc) · 1.35 KB
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
exports.version = '0.0.1';
exports.IRSend = require('./irsend');
exports.irsend = new exports.IRSend();
exports.IRRecord = require('./irrecord');
exports.irrecord = new exports.IRRecord();
exports.remotes = {};
exports.init = function(callback) {
exports.irsend.list('', '', irsendCallback);
function irsendCallback(error, stdout, stderr) {
exports._populateRemotes(error, stdout, stderr);
exports._populateCommands();
if (callback) callback();
}
return true;
};
// Private
exports._populateRemotes = function(error, stdout, stderr) {
var remotes = stderr.split('\n');
exports.remotes = {};
remotes.forEach(function(element, index, array) {
var remoteName = element.match(/\s(.*)$/);
if (remoteName) exports.remotes[remoteName[1]] = [];
});
};
exports._populateCommands = function() {
for (var remote in exports.remotes) {
(function(remote) {
exports.irsend.list(remote, '', function(error, stdout, stderr) {
exports._populateRemoteCommands(remote, error, stdout, stderr);
});
})(remote);
}
};
exports._populateRemoteCommands = function(remote, error, stdout, stderr) {
var commands = stderr.split('\n');
commands.forEach(function(element, index, array) {
var commandName = element.match(/\s.*\s(.*)$/);
if (commandName && commandName[1]) exports.remotes[remote].push(commandName[1]);
});
};