From 77b765e8f069e0c28e0f5b57057530d420f36a47 Mon Sep 17 00:00:00 2001 From: Harald Rietman Date: Sat, 15 Jul 2017 10:15:07 +0200 Subject: [PATCH] Refactored handling retry timer --- .../xiaomi-socket-wifi.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/node-red-contrib-xiaomi-socket-wifi/xiaomi-socket-wifi.js b/node-red-contrib-xiaomi-socket-wifi/xiaomi-socket-wifi.js index 319119b..825a852 100644 --- a/node-red-contrib-xiaomi-socket-wifi/xiaomi-socket-wifi.js +++ b/node-red-contrib-xiaomi-socket-wifi/xiaomi-socket-wifi.js @@ -164,8 +164,15 @@ module.exports = function(RED) { } RED.nodes.registerType("xiaomi-plug-wifi", XiaomiPlugWifiNode); - process.on('unhandledRejection', function(reason, p){ - console.log("Possibly Unhandled Rejection at: Promise ", p, " reason: ", reason); - // application specific logging here + process.on('unhandledRejection', function(reason, p) { + // console.log("Possibly Unhandled Rejection at: Promise ", p, " reason: ", reason); + var message = reason + ""; + if (message.indexOf("Call to device timed out") >= 0) { + if (this.plug) { + console.log("Issue with miio package; discard plug and reconnect."); + this.plug.destroy(); + this.plug = null; + } + } }); }