From 3a57ff7afb2cbc2a22f1514dfb0f0c4d465177e8 Mon Sep 17 00:00:00 2001 From: Sherwin Faria Date: Sun, 23 Feb 2020 15:07:24 -0600 Subject: [PATCH 01/14] Change to update on key down --- lutron-config.js | 8 ++++---- lutron-status.js | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lutron-config.js b/lutron-config.js index 6f7f958..46031e0 100644 --- a/lutron-config.js +++ b/lutron-config.js @@ -43,15 +43,15 @@ module.exports = function (RED) { console.log('telnet close'); }); this.telnet.on('error', function () { - console.log('telent error'); + console.log('telnet error'); }); this.telnet.on('failedlogin', function () { - console.log('telent failed login'); + console.log('telnet failed login'); }); this.lutronSend = function (msg, fn) { - this.telent.getSocket().write(msg + '\n', fn); + this.telnet.getSocket().write(msg + '\n', fn); } - this.lutrongUpdate = function (deviceId, fn) { + this.lutronUpdate = function (deviceId, fn) { this.lutronSend('?OUTPUT,' + deviceId + ',1', fn); } this.lutronSend = function (deviceId, val, fn) { diff --git a/lutron-status.js b/lutron-status.js index 1ce115e..39bcd8a 100644 --- a/lutron-status.js +++ b/lutron-status.js @@ -17,10 +17,10 @@ module.exports = function (RED) { /* for dimmer action is always 1 for pico action.param - FullOn => a=2, p=4 - up => a=5, p=4 - down => a=6 p=4 - off => a=4, p=4 + FullOn => a=2, p=3 + up => a=5, p=3 + down => a=6 p=3 + off => a=4, p=3 for on off switch action =1 p=0 or 100 */ @@ -29,7 +29,7 @@ module.exports = function (RED) { node.send({ payload: value }); - } else if (value === 4) { + } else if (value === 3) { var m = ''; if (action === 2) m = 'on'; From 21d625443994f9679520d72ae4094bbfcf8de163 Mon Sep 17 00:00:00 2001 From: Sherwin Faria Date: Sun, 23 Feb 2020 15:09:31 -0600 Subject: [PATCH 02/14] Update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b0fd1e8..0df5cf7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-lutron", - "version": "1.0.3", + "version": "1.0.4", "description": "A node for communicating with Lutron Caseta Pro Hub", "main": "index.js", "scripts": { From 0182e76585b1e2a31fb8650a1966050bd28b9d84 Mon Sep 17 00:00:00 2001 From: Sherwin Faria Date: Thu, 27 Feb 2020 00:03:57 -0600 Subject: [PATCH 03/14] Add configuration --- lutron-config.html | 7 +++++++ lutron-config.js | 1 + lutron-status.js | 2 ++ 3 files changed, 10 insertions(+) diff --git a/lutron-config.html b/lutron-config.html index 7173c44..6358be4 100644 --- a/lutron-config.html +++ b/lutron-config.html @@ -14,6 +14,9 @@ }, timeout: { value: 45000 + }, + includeAction: { + value: false } }, label: function () { @@ -99,6 +102,10 @@ +
+ + +

Device mapping table

diff --git a/lutron-config.js b/lutron-config.js index 46031e0..837aaf0 100644 --- a/lutron-config.js +++ b/lutron-config.js @@ -14,6 +14,7 @@ module.exports = function (RED) { this.deviceMap = config.deviceMap; node.devices = {}; node.lutronEvent = new events.EventEmitter(); + node.includeAction = config.includeAction; var params = { host: this.lutronLoc, port: this.port, diff --git a/lutron-status.js b/lutron-status.js index 39bcd8a..b17c7ad 100644 --- a/lutron-status.js +++ b/lutron-status.js @@ -8,6 +8,8 @@ module.exports = function (RED) { // register a callback on config node so that it can call this // node // then it will call the this.send(msg), msg = {payload: "hi"} + console.log(typeof configNode.includeAction); + console.log(configNode.includeAction); configNode.lutronEvent.on('data', (function (node, d) { if (node.devId && node.devId !== 0) { if (d.cmd === '~' && (d.type === 'DEVICE' || d.type === 'OUTPUT') && From b433f054bc84bb2afe431c6b5a974f3f9311c55e Mon Sep 17 00:00:00 2001 From: Sherwin Faria Date: Thu, 27 Feb 2020 00:31:21 -0600 Subject: [PATCH 04/14] Send action data --- lutron-status.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lutron-status.js b/lutron-status.js index b17c7ad..6378291 100644 --- a/lutron-status.js +++ b/lutron-status.js @@ -5,11 +5,10 @@ module.exports = function (RED) { var configNode = RED.nodes.getNode(status.confignode); this.devName = status.name; this.devId = parseInt(configNode.deviceMap[this.devName]); + this.sendObj = !!configNode.includeAction; // register a callback on config node so that it can call this // node // then it will call the this.send(msg), msg = {payload: "hi"} - console.log(typeof configNode.includeAction); - console.log(configNode.includeAction); configNode.lutronEvent.on('data', (function (node, d) { if (node.devId && node.devId !== 0) { if (d.cmd === '~' && (d.type === 'DEVICE' || d.type === 'OUTPUT') && @@ -29,10 +28,10 @@ module.exports = function (RED) { if (action == '1') { // either dimmre of switch node.send({ - payload: value + payload: node.sendObj ? d : value }); - } else if (value === 3) { - var m = ''; + } else if (value === 3 || node.sendObj) { + var m = action; if (action === 2) m = 'on'; else if (action === 5) @@ -41,8 +40,11 @@ module.exports = function (RED) { m = 'down'; else if (action === 4) m = 'off'; + + d.action = m; + d.param = value === 3 ? 'keydown' : 'keyup'; node.send({ - payload: m + payload: node.sendObj ? d : m }); } } From f735891f7940510f2448638bd8115d733a4f2cd4 Mon Sep 17 00:00:00 2001 From: inquirer Date: Mon, 8 Nov 2021 20:42:25 -0600 Subject: [PATCH 05/14] Add logs for disconnect --- lutron-config.html | 2 +- lutron-config.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lutron-config.html b/lutron-config.html index 6358be4..17e3d6d 100644 --- a/lutron-config.html +++ b/lutron-config.html @@ -103,7 +103,7 @@
- +
diff --git a/lutron-config.js b/lutron-config.js index 837aaf0..8a62e57 100644 --- a/lutron-config.js +++ b/lutron-config.js @@ -49,6 +49,12 @@ module.exports = function (RED) { this.telnet.on('failedlogin', function () { console.log('telnet failed login'); }); + this.telnet.on('timeout', function () { + console.log('telnet timeout'); + }); + this.telnet.on('end', function () { + console.log('telnet remote ended connection'); + }); this.lutronSend = function (msg, fn) { this.telnet.getSocket().write(msg + '\n', fn); } From b8a5bdfb6bc8ede636c81f3083d25da34aa1c211 Mon Sep 17 00:00:00 2001 From: inquirer Date: Mon, 8 Nov 2021 22:09:44 -0600 Subject: [PATCH 06/14] Add status updates and cleanup handlers --- lutron-config.js | 42 ++++++++++++++++++++++++++++++++++-------- lutron-status.js | 3 +++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/lutron-config.js b/lutron-config.js index 8a62e57..922c44b 100644 --- a/lutron-config.js +++ b/lutron-config.js @@ -11,9 +11,10 @@ module.exports = function (RED) { node.connected = false; node.telnet = new Telnet(); node.port = 23; - this.deviceMap = config.deviceMap; + node.deviceMap = config.deviceMap; node.devices = {}; node.lutronEvent = new events.EventEmitter(); + node.statusEvent = new events.EventEmitter(); node.includeAction = config.includeAction; var params = { host: this.lutronLoc, @@ -32,29 +33,46 @@ module.exports = function (RED) { var str = '?OUTPUT,' + devId + ',1'; this.telnet.getSocket().write(str + '\n'); }; + + const updateStatus = (connected, msg) => { + this.statusEvent.emit('update', { + fill: connected ? 'green' : 'red', + shape: 'dot', + text: msg + }); + }; + + // Telnet handlers this.telnet.on('data', (function (self, pkt) { self.lutronRecv(pkt); }).bind(null, node)); this.telnet.on('connect', function () { this.connected = true; - console.log('telnet connect'); + this.log('telnet connect'); + updateStatus(true, 'connected'); }); this.telnet.on('close', function () { this.connected = false; - console.log('telnet close'); + this.log('telnet close'); + updateStatus(false, 'closed'); }); this.telnet.on('error', function () { - console.log('telnet error'); + this.warn('telnet error'); + updateStatus(false, 'telnet error'); }); this.telnet.on('failedlogin', function () { - console.log('telnet failed login'); + this.warn('telnet failed login'); + updateStatus(false, 'login failed'); }); this.telnet.on('timeout', function () { - console.log('telnet timeout'); + this.log('telnet timeout'); }); this.telnet.on('end', function () { - console.log('telnet remote ended connection'); + this.warn('telnet remote ended connection'); + updateStatus(false, 'ended'); }); + + // Lutron handlers this.lutronSend = function (msg, fn) { this.telnet.getSocket().write(msg + '\n', fn); } @@ -73,7 +91,7 @@ module.exports = function (RED) { var deviceId = parseInt(cs[1]) var action = parseInt(cs[2]) var param = parseFloat(cs[3]) - // console.log('[',cmd,',', type, ',',deviceId, + // this.log('[',cmd,',', type, ',',deviceId, // ',', action,',', param,']') this.lutronEvent.emit('data', { cmd: cmd, @@ -93,6 +111,14 @@ module.exports = function (RED) { } } } + + // Cleanup on close + this.on('close', function(done) { + this.telnet.end() + .then(() => done()) + .catch(() => this.telnet.destroy().then(() => done())); + }); + this.telnet.connect(params); } RED.nodes.registerType('lutron-config', LutronConfigNode); diff --git a/lutron-status.js b/lutron-status.js index 6378291..1a6f903 100644 --- a/lutron-status.js +++ b/lutron-status.js @@ -54,6 +54,9 @@ module.exports = function (RED) { }); } }).bind(null, this)); + + // Update node status + configNode.statusEvent.on('update', status => this.status(status)); } RED.nodes.registerType('lutron-status', LutronStatusNode); } \ No newline at end of file From 9c14e4a7deffe6bc68169530095025ae20396de2 Mon Sep 17 00:00:00 2001 From: inquirer Date: Mon, 8 Nov 2021 22:23:37 -0600 Subject: [PATCH 07/14] replace this references --- lutron-config.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lutron-config.js b/lutron-config.js index 922c44b..d9da7ca 100644 --- a/lutron-config.js +++ b/lutron-config.js @@ -35,7 +35,7 @@ module.exports = function (RED) { }; const updateStatus = (connected, msg) => { - this.statusEvent.emit('update', { + node.statusEvent.emit('update', { fill: connected ? 'green' : 'red', shape: 'dot', text: msg @@ -47,28 +47,28 @@ module.exports = function (RED) { self.lutronRecv(pkt); }).bind(null, node)); this.telnet.on('connect', function () { - this.connected = true; - this.log('telnet connect'); + node.connected = true; + node.log('telnet connect'); updateStatus(true, 'connected'); }); this.telnet.on('close', function () { - this.connected = false; - this.log('telnet close'); + node.connected = false; + node.log('telnet close'); updateStatus(false, 'closed'); }); this.telnet.on('error', function () { - this.warn('telnet error'); + node.warn('telnet error'); updateStatus(false, 'telnet error'); }); this.telnet.on('failedlogin', function () { - this.warn('telnet failed login'); + node.warn('telnet failed login'); updateStatus(false, 'login failed'); }); this.telnet.on('timeout', function () { - this.log('telnet timeout'); + node.log('telnet timeout'); }); this.telnet.on('end', function () { - this.warn('telnet remote ended connection'); + node.warn('telnet remote ended connection'); updateStatus(false, 'ended'); }); @@ -113,7 +113,7 @@ module.exports = function (RED) { } // Cleanup on close - this.on('close', function(done) { + node.on('close', function(done) { this.telnet.end() .then(() => done()) .catch(() => this.telnet.destroy().then(() => done())); From 5e8d465e93afd58e7bcef3cf41773fa60624a462 Mon Sep 17 00:00:00 2001 From: inquirer Date: Mon, 8 Nov 2021 22:45:10 -0600 Subject: [PATCH 08/14] Additional cleanup --- lutron-config.js | 7 ++++--- lutron-status.js | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lutron-config.js b/lutron-config.js index d9da7ca..ef5b534 100644 --- a/lutron-config.js +++ b/lutron-config.js @@ -114,9 +114,10 @@ module.exports = function (RED) { // Cleanup on close node.on('close', function(done) { - this.telnet.end() - .then(() => done()) - .catch(() => this.telnet.destroy().then(() => done())); + node.log('Node shutting down'); + node.telnet.end() + .then(() => done()) + .catch(() => this.telnet.destroy().then(() => done())); }); this.telnet.connect(params); diff --git a/lutron-status.js b/lutron-status.js index 1a6f903..16e4484 100644 --- a/lutron-status.js +++ b/lutron-status.js @@ -55,8 +55,13 @@ module.exports = function (RED) { } }).bind(null, this)); + const statusHandler = status => this.status(status); + // Update node status - configNode.statusEvent.on('update', status => this.status(status)); + configNode.statusEvent.on('update', statusHandler); + + // Cleanup on close + node.on('close', (done) => configNode.statusEvent.removeListener('update', statusHandler)); } RED.nodes.registerType('lutron-status', LutronStatusNode); } \ No newline at end of file From cdf12ec391e8780c4316a032796702e3210ab3c4 Mon Sep 17 00:00:00 2001 From: inquirer Date: Mon, 8 Nov 2021 22:47:40 -0600 Subject: [PATCH 09/14] Fix reference --- lutron-config.js | 4 ++-- lutron-status.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lutron-config.js b/lutron-config.js index ef5b534..4f3332d 100644 --- a/lutron-config.js +++ b/lutron-config.js @@ -7,7 +7,7 @@ module.exports = function (RED) { function LutronConfigNode(config) { RED.nodes.createNode(this, config); this.lutronLoc = config.ipaddress; - var node = this; + const node = this; node.connected = false; node.telnet = new Telnet(); node.port = 23; @@ -16,7 +16,7 @@ module.exports = function (RED) { node.lutronEvent = new events.EventEmitter(); node.statusEvent = new events.EventEmitter(); node.includeAction = config.includeAction; - var params = { + const params = { host: this.lutronLoc, port: this.port, shellPrompt: 'GNET>', diff --git a/lutron-status.js b/lutron-status.js index 16e4484..61fe51f 100644 --- a/lutron-status.js +++ b/lutron-status.js @@ -61,7 +61,7 @@ module.exports = function (RED) { configNode.statusEvent.on('update', statusHandler); // Cleanup on close - node.on('close', (done) => configNode.statusEvent.removeListener('update', statusHandler)); + this.on('close', (done) => configNode.statusEvent.removeListener('update', statusHandler)); } RED.nodes.registerType('lutron-status', LutronStatusNode); } \ No newline at end of file From 64e0859ed9610c6f0a051408a815ddaf3bdf1188 Mon Sep 17 00:00:00 2001 From: inquirer Date: Mon, 8 Nov 2021 22:50:48 -0600 Subject: [PATCH 10/14] Remove done callback --- lutron-status.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lutron-status.js b/lutron-status.js index 61fe51f..a346ae8 100644 --- a/lutron-status.js +++ b/lutron-status.js @@ -61,7 +61,7 @@ module.exports = function (RED) { configNode.statusEvent.on('update', statusHandler); // Cleanup on close - this.on('close', (done) => configNode.statusEvent.removeListener('update', statusHandler)); + this.on('close', () => configNode.statusEvent.removeListener('update', statusHandler)); } RED.nodes.registerType('lutron-status', LutronStatusNode); } \ No newline at end of file From ad69f267279147922c60b0819e7f1728842ee945 Mon Sep 17 00:00:00 2001 From: inquirer Date: Tue, 1 Feb 2022 18:51:23 -0600 Subject: [PATCH 11/14] Support reconnecting --- lutron-config.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lutron-config.js b/lutron-config.js index 4f3332d..9b73c6a 100644 --- a/lutron-config.js +++ b/lutron-config.js @@ -42,6 +42,11 @@ module.exports = function (RED) { }); }; + const reconnect = () => { + // Try reconnecting in 1 minute + setTimeout(() => this.telnet.connect(params), 60000); + } + // Telnet handlers this.telnet.on('data', (function (self, pkt) { self.lutronRecv(pkt); @@ -52,12 +57,16 @@ module.exports = function (RED) { updateStatus(true, 'connected'); }); this.telnet.on('close', function () { + if (node.connected) { + node.log('telnet close'); + } node.connected = false; - node.log('telnet close'); updateStatus(false, 'closed'); }); this.telnet.on('error', function () { - node.warn('telnet error'); + if (node.connected) { + node.warn('telnet error'); + } updateStatus(false, 'telnet error'); }); this.telnet.on('failedlogin', function () { @@ -65,10 +74,17 @@ module.exports = function (RED) { updateStatus(false, 'login failed'); }); this.telnet.on('timeout', function () { - node.log('telnet timeout'); + if (node.connected) { + node.log('telnet timeout'); + } }); this.telnet.on('end', function () { - node.warn('telnet remote ended connection'); + if (node.connected) { + // This happens periodically (on bridge updates?) + // so try reconnecting afterwards + node.warn('telnet remote ended connection'); + reconnect(); + } updateStatus(false, 'ended'); }); @@ -115,6 +131,7 @@ module.exports = function (RED) { // Cleanup on close node.on('close', function(done) { node.log('Node shutting down'); + node.connected = false; node.telnet.end() .then(() => done()) .catch(() => this.telnet.destroy().then(() => done())); From f48cca2972f00ddb30f688a4b525a80c8d9d7927 Mon Sep 17 00:00:00 2001 From: inquirer Date: Tue, 1 Feb 2022 19:05:23 -0600 Subject: [PATCH 12/14] Add reconnect message --- lutron-config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lutron-config.js b/lutron-config.js index 9b73c6a..8886109 100644 --- a/lutron-config.js +++ b/lutron-config.js @@ -44,6 +44,7 @@ module.exports = function (RED) { const reconnect = () => { // Try reconnecting in 1 minute + node.log('reconnecting telnet') setTimeout(() => this.telnet.connect(params), 60000); } From d81ee4a7dca48dba1b23b2548f0afff93b805d51 Mon Sep 17 00:00:00 2001 From: inquirer Date: Sun, 20 Feb 2022 21:25:14 -0600 Subject: [PATCH 13/14] - Add reconnecting status - Fix typo --- lutron-config.js | 5 ++++- lutron-control.html | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lutron-config.js b/lutron-config.js index 8886109..6045fc8 100644 --- a/lutron-config.js +++ b/lutron-config.js @@ -80,13 +80,16 @@ module.exports = function (RED) { } }); this.telnet.on('end', function () { + let status = 'ended'; if (node.connected) { // This happens periodically (on bridge updates?) // so try reconnecting afterwards node.warn('telnet remote ended connection'); + status = 'reconnecting'; reconnect(); } - updateStatus(false, 'ended'); + + updateStatus(false, status); }); // Lutron handlers diff --git a/lutron-control.html b/lutron-control.html index 25f1874..3dd0985 100644 --- a/lutron-control.html +++ b/lutron-control.html @@ -42,7 +42,7 @@
-