Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Commit

Permalink
Fixed duplicated messages when restarting client #17
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Mar 19, 2019
1 parent c5057c6 commit f88f607
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
6 changes: 4 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ app.post('/api/settings', function(req, res) {
jsonStore.put(store.settings, req.body)
.then(data => {
res.json({success: true, message: "Configuration updated successfully"});
gw.close(() => startGateway());
gw.close();
startGateway();
}).catch(err => {
debug(err);
res.json({success: false, message: err.message})
Expand Down Expand Up @@ -183,7 +184,8 @@ process.removeAllListeners('SIGINT');

process.on('SIGINT', function() {
debug('Closing...');
gw.close(() => process.exit());
gw.close();
process.exit();
});

module.exports = app;
21 changes: 4 additions & 17 deletions lib/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,29 +278,16 @@ function parsePayload(payload, value, valueConf, config){
/**
* Method used to close clients connection, use this before destroy
*/
Gateway.prototype.close = function (callback) {
Gateway.prototype.close = function () {
this.closed = true;

debug("Closing Gateway...")

if(this.mqtt)
this.mqtt.close();

if(this.zwave)
this.zwave.close(callback);
}


/**
* Method used to update client
*/
Gateway.prototype.update = function (config) {
debug(`Restarting Gateway after update...`);
var self = this;
this.close(() => init.call(self, config));
}


function sendLog(self, ...args){
console.log(`Gateway:`, ...args);
this.zwave.close();
}

module.exports = Gateway
5 changes: 2 additions & 3 deletions lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,18 +458,17 @@ function valueRemoved(nodeid, comclass, instance, index) {
/**
* Method used to close client connection, use this before destroy
*/
ZwaveClient.prototype.close = function (callback) {
ZwaveClient.prototype.close = function () {
if(this.tail){
this.tail.unwatch();
}

if(this.connected && this.client){
this.connected = false;
this.closed = true;
this.client.removeAllListeners();
this.client.disconnect(this.cfg.port);
}

if(callback) setTimeout(callback, 2000);
}

/**
Expand Down

0 comments on commit f88f607

Please sign in to comment.