diff --git a/lib/roles/provider.js b/lib/roles/provider.js index a28e1d95..ec00274e 100644 --- a/lib/roles/provider.js +++ b/lib/roles/provider.js @@ -128,23 +128,31 @@ module.exports = function(options) { lists.all.push(device.id) delayedTotals() - // The device object will be kept up to date by the tracker, except - // our custom "present" property + // Will be set to false when the device is removed _.assign(device, { present: true }) // When any event occurs on the added device - function deviceListener(type) { + function deviceListener(type, updatedDevice) { // Okay, this is a bit unnecessary but it allows us to get rid of an // ugly switch statement and return to the original style. - privateTracker.emit(type) + privateTracker.emit(type, updatedDevice) } // When the added device changes - function changeListener() { + function changeListener(updatedDevice) { register.then(function() { - log.info('Device "%s" is now "%s"', device.id, device.type) + log.info( + 'Device "%s" is now "%s" (was "%s")' + , device.id + , updatedDevice.type + , device.type + ) + + _.assign(device, { + type: updatedDevice.type + }) // Tell others the device changed push.send([ @@ -160,7 +168,7 @@ module.exports = function(options) { } // When the added device gets removed - function removeListener() { + function removeListener(updatedDevice) { register.then(function() { log.info('Lost device "%s" (%s)', device.id, device.type)