diff --git a/huawei-router/huawei-router.html b/huawei-router/huawei-router.html
index 9a6f86c..6871f8f 100644
--- a/huawei-router/huawei-router.html
+++ b/huawei-router/huawei-router.html
@@ -103,7 +103,7 @@
Output
-
+
diff --git a/huawei-router/huawei-router.js b/huawei-router/huawei-router.js
index 1e18bf9..7b5af6f 100644
--- a/huawei-router/huawei-router.js
+++ b/huawei-router/huawei-router.js
@@ -14,7 +14,7 @@ module.exports = function (RED) {
// Add 298 seconds to current time as timeout
this.sessionTimeout = node.now + 298000
if (!this.connection) {
- // Make new session
+ // Make new session
this.connection = new huaweiLteApi.Connection('http://' + n.user + ':' + n.pass + '@' + n.url)
await this.connection.ready
}
@@ -74,8 +74,9 @@ module.exports = function (RED) {
const node = this
node.on('input', async function (msg, send, done) {
const allowedModes = ['on', 1, true, 'off', 0, false, 'toggle', 'off-on']
- msg.mode = msg.mode || node.mode || 'off-on'
- msg.mode = msg.mode.toLowerCase()
+ if (typeof (msg.mode) === 'undefined') {
+ msg.mode = node.mode
+ } else if (typeof (msg.mode) === 'string') { msg.mode = msg.mode.toLowerCase() }
if (!allowedModes.includes(msg.mode)) {
done('Input mode is not understood')
return
@@ -100,8 +101,7 @@ module.exports = function (RED) {
msg.payload = result
msg.state = result === 'OK' ? 1 - Number(dataswitch) : Number(dataswitch)
send(msg)
- } else {
- // if (msg.mode === 'off-on') {
+ } else if (msg.mode === 'off-on') {
await dialUp.setMobileDataswitch(0)
const result = await dialUp.setMobileDataswitch(1)
msg.payload = result
diff --git a/package-lock.json b/package-lock.json
index 0eb0b8b..92fb6bf 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-huawei-router",
- "version": "1.0.3",
+ "version": "1.0.4",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index 58f7d26..b47134a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-huawei-router",
- "version": "1.0.3",
+ "version": "1.0.4",
"description": "",
"scripts": {
"pretest": "npm install node-red-node-test-helper node-red mocha --no-save",
diff --git a/test/huawei-mobiledata_spec.test.js b/test/huawei-mobiledata_spec.test.js
index b474310..04e5710 100644
--- a/test/huawei-mobiledata_spec.test.js
+++ b/test/huawei-mobiledata_spec.test.js
@@ -58,4 +58,66 @@ describe('huawei-mobiledata Node', function () {
n1.receive({ payload: '', mode: 'off-on' })
})
})
+ it('should turn data off', function (done) {
+ const flow = [
+ {
+ id: 'n0',
+ type: 'huawei-config',
+ user: process.env.ROUTER_USER,
+ pass: process.env.ROUTER_PASSWORD,
+ url: process.env.ROUTER_URL
+ },
+ { id: 'n1', type: 'huawei-mobiledata', wires: [['n2']], server: 'n0' },
+ { id: 'n2', type: 'helper' }
+ ]
+ helper.load(testNode, flow, function () {
+ helper.getNode('n0')
+ const n1 = helper.getNode('n1')
+ const n2 = helper.getNode('n2')
+ n2.on('input', function (msg) {
+ console.log(msg)
+ msg.payload.should.equal('OK')
+ msg.should.property('state').which.is.a.Number()
+ msg.mode.should.equal(false)
+ msg.state.should.equal(0)
+ done()
+ })
+ n1.on('call:error', function (err) {
+ console.error(err.firstArg)
+ done(new Error(err.firstArg))
+ })
+ n1.receive({ payload: '', mode: false })
+ })
+ })
+ it('should turn data on', function (done) {
+ const flow = [
+ {
+ id: 'n0',
+ type: 'huawei-config',
+ user: process.env.ROUTER_USER,
+ pass: process.env.ROUTER_PASSWORD,
+ url: process.env.ROUTER_URL
+ },
+ { id: 'n1', type: 'huawei-mobiledata', wires: [['n2']], server: 'n0' },
+ { id: 'n2', type: 'helper' }
+ ]
+ helper.load(testNode, flow, function () {
+ helper.getNode('n0')
+ const n1 = helper.getNode('n1')
+ const n2 = helper.getNode('n2')
+ n2.on('input', function (msg) {
+ console.log(msg)
+ msg.payload.should.equal('OK')
+ msg.should.property('state').which.is.a.Number()
+ msg.mode.should.equal(1)
+ msg.state.should.equal(1)
+ done()
+ })
+ n1.on('call:error', function (err) {
+ console.error(err.firstArg)
+ done(new Error(err.firstArg))
+ })
+ n1.receive({ payload: '', mode: 1 })
+ })
+ })
})