add be i118n version with test

This commit is contained in:
Dave Conway-Jones
2015-07-14 21:03:07 +01:00
parent ee5ff8b010
commit 1ff66443fb
6 changed files with 97 additions and 26 deletions

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2014 IBM Corp.
* Copyright 2014, 2015 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,33 +16,40 @@
module.exports = function(RED) {
"use strict";
function RbeNode(n) {
RED.nodes.createNode(this,n);
this.func = n.func || "rbe";
this.gap = n.gap || 0;
this.gap = n.gap || "0";
this.pc = false;
if (this.gap.substr(-1) === "%") {
this.pc = true;
this.gap = parseFloat(this.gap);
}
this.g = this.gap;
var node = this;
var previous = null;
node.previous = {};
this.on("input",function(msg) {
if (msg.hasOwnProperty("payload")) {
var t = msg.topic || "_no_topic";
if (this.func === "rbe") {
if (msg.payload != previous) {
previous = msg.payload;
if (msg.payload != node.previous[t]) {
node.previous[t] = msg.payload;
node.send(msg);
}
}
else {
var n = parseFloat(msg.payload);
if (!isNaN(n)) {
if (previous == null) { previous = n - node.gap; }
if (Math.abs(n - previous) >= node.gap) {
previous = n;
if (node.pc) { node.gap = (node.previous[t] * node.g / 100) || 0; }
if (!node.previous.hasOwnProperty(t)) { node.previous[t] = n - node.gap; }
if (Math.abs(n - node.previous[t]) >= node.gap) {
node.previous[t] = n;
node.send(msg);
}
}
else {
node.warn("no number found in payload");
node.warn(RED._("rbe.warn.nonumber"));
}
}
} // ignore msg with no payload property.