-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathneato-action.js
34 lines (29 loc) · 1.03 KB
/
neato-action.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
var TranslatorHelper = require('./Translator.js');
var translator;
var node;
module.exports = function(RED)
{
function NeatoActionNode(config) {
RED.nodes.createNode(this, config);
node = this;
var configNode = RED.nodes.getNode(config.confignode);
if (configNode !== null) this.language = configNode.language;
else this.language = "en";
translator = new TranslatorHelper(this.language);
//handle input message
node.on('input', function (msg) {
handleInputMsg(msg);
});
}
function handleInputMsg(msg)
{
if (msg === undefined || msg === null) return;
if (msg.payload === undefined || msg.payload === null) return;
if (msg.payload.action === undefined || msg.payload.action === null)
{
node.send({payload: "", topic:"action"});
}
node.send({payload: translator.getString("action_" + msg.payload.action.toString()), topic:"action"});
}
RED.nodes.registerType("neato-action", NeatoActionNode);
};