From eabf45526dd287ddd83745632c649b9dbaab0b77 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Tue, 3 Nov 2015 06:37:53 -0800 Subject: [PATCH] Guard against multiple WeMo callbacks Closes #296 --- accessories/WeMo.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/accessories/WeMo.js b/accessories/WeMo.js index 5cbc3f4..48e0808 100644 --- a/accessories/WeMo.js +++ b/accessories/WeMo.js @@ -89,7 +89,15 @@ WeMoAccessory.prototype.setPowerOn = function(powerOn, callback) { var binaryState = powerOn ? 1 : 0; // wemo langauge this.log("Setting power state on the '%s' to %s", this.wemoName, binaryState); + var callbackWasCalled = false; + this.device.setBinaryState(binaryState, function(err, result) { + if (callbackWasCalled) { + this.log("WARNING: setBinaryState called its callback more than once! Discarding the second one."); + } + + callbackWasCalled = true; + if (!err) { this.log("Successfully set power state on the '%s' to %s", this.wemoName, binaryState); callback(null);