Skip to content

Commit bc91e69

Browse files
Apollon77KhaosT
authored andcommitted
catch oldValue in setValue directly at the beginning (homebridge#687)
1 parent da502c3 commit bc91e69

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/Characteristic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ Characteristic.prototype.setValue = function(newValue, callback, context, connec
315315

316316
newValue = this.validateValue(newValue); //validateValue returns a value that has be cooerced into a valid value.
317317

318+
var oldValue = this.value;
319+
318320
if (this.listeners('set').length > 0) {
319321

320322
// allow a listener to handle the setting of this value, and wait for completion
@@ -328,7 +330,6 @@ Characteristic.prototype.setValue = function(newValue, callback, context, connec
328330
if (newValue === undefined || newValue === null)
329331
newValue = this.getDefaultValue();
330332
// setting the value was a success; so we can cache it now
331-
var oldValue = this.value;
332333
this.value = newValue;
333334
if (callback) callback();
334335

@@ -343,7 +344,6 @@ Characteristic.prototype.setValue = function(newValue, callback, context, connec
343344
if (newValue === undefined || newValue === null)
344345
newValue = this.getDefaultValue();
345346
// no one is listening to the 'set' event, so just assign the value blindly
346-
var oldValue = this.value;
347347
this.value = newValue;
348348
if (callback) callback();
349349

0 commit comments

Comments
 (0)