From 436f169fd436433d848ea7ddaf1c4538ed10b9b3 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Sat, 11 Apr 2020 10:47:47 +0100 Subject: [PATCH] More Wemo update (#631) * Reduce resubscription time Halve the resubscrciption timeout to make sure event subscriptions get renewed * Big Update Includes: - New lookup node to check state of a device - Fix dimming control for lights - Fix light group control - Set the node label to match the device name - The event now includes the text description of the light capability * Fix groups properly * Fix travis error with comparitor * Bump node-ssdp version * Add extra check for empty results in discovery * Bump twitter to 280 chars fixes #371 * Bump twitter node version * Remove extra whitespace * Add catch for HTTP timeout If the device drops off line then with no catch for the timeout Node-RED will crash Should fix #616 * More timeout catch blocks * Version bump * Bump Wemo version --- hardware/wemo/lib/wemo.js | 29 ++++++++++++++++++++--------- hardware/wemo/package.json | 2 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/hardware/wemo/lib/wemo.js b/hardware/wemo/lib/wemo.js index 2e8d6f9b..acb6fc5c 100644 --- a/hardware/wemo/lib/wemo.js +++ b/hardware/wemo/lib/wemo.js @@ -215,6 +215,10 @@ WeMoNG.prototype.start = function start() { }); }); + post_request.on('timeout', function(){ + post_request.abort(); + }); + post_request.write(util.format(getenddevs.body, udn)); post_request.end(); @@ -291,9 +295,9 @@ WeMoNG.prototype.toggleSocket = function toggleSocket(socket, on) { console.log("%j", postoptions); }); - post_request.on('timeout', function (e) { - console.log(e); - console.log("%j"); + post_request.on('timeout', function () { + console.log("Timeout"); + post_request.abort(); }); var body = [ @@ -347,6 +351,11 @@ WeMoNG.prototype.getSocketStatus = function getSocketStatus(socket) { def.reject(); }); + post_request.on('timeout', function(){ + post_request.abort(); + def.reject(); + }); + post_request.write(getSocketState.body); post_request.end(); @@ -409,9 +418,9 @@ WeMoNG.prototype.getLightStatus = function getLightStatus(light) { def.reject(); }); - post_request.on('timeout', function (e) { - console.log(e); - console.log("%j"); + post_request.on('timeout', function () { + console.log("Timeout"); + post_request.abort(); def.reject(); }); @@ -451,9 +460,9 @@ WeMoNG.prototype.setStatus = function setStatus(light, capability, value) { console.log("%j", postoptions); }); - post_request.on('timeout', function (e) { - console.log(e); - console.log("%j"); + post_request.on('timeout', function () { + console.log("Timeout"); + post_request.abort(); }); //console.log(util.format(setdevstatus.body, light.id, capability, value)); @@ -493,9 +502,11 @@ WeMoNG.prototype.parseEvent = function parseEvent(evt) { def.resolve(msg); } else { console.log("unhandled wemo event type \n%s", util.inspect(prop, {depth:null})); + } } else { //error + def.reject(); } }); diff --git a/hardware/wemo/package.json b/hardware/wemo/package.json index fd668081..b116b9a6 100644 --- a/hardware/wemo/package.json +++ b/hardware/wemo/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-wemo", - "version": "0.1.16", + "version": "0.1.17", "description": "Input and Output nodes for Belkin WeMo devices", "repository": "https://github.com/node-red/node-red-nodes/tree/master/hardware", "main": "WeMoNG.js",