From baae52f1248ebbc195c814b5195d26fb8f19946e Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 22 May 2024 16:24:45 +0200 Subject: [PATCH] uses previous device in device update handler --- lib/bindings/AMQPBinding.js | 2 +- lib/bindings/ARGOBinding.js | 2 +- lib/bindings/HTTPBinding.js | 10 ++++++---- lib/bindings/MQTTBinding.js | 2 +- lib/iotagent-json.js | 12 +++++++++--- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/bindings/AMQPBinding.js b/lib/bindings/AMQPBinding.js index 1d82c075..7dd38a85 100644 --- a/lib/bindings/AMQPBinding.js +++ b/lib/bindings/AMQPBinding.js @@ -246,7 +246,7 @@ function deviceProvisioningHandler(device, callback) { * * @param {Object} device Device object containing all the information about the provisioned device. */ -function deviceUpdatingHandler(device, callback) { +function deviceUpdatingHandler(device, oldDevice, callback) { callback(null, device); } diff --git a/lib/bindings/ARGOBinding.js b/lib/bindings/ARGOBinding.js index 46fd11db..ad81fd59 100644 --- a/lib/bindings/ARGOBinding.js +++ b/lib/bindings/ARGOBinding.js @@ -522,7 +522,7 @@ function deviceProvisioningHandler(device, callback) { * * @param {Object} device Device object containing all the information about the updated device. */ -function deviceUpdatingHandler(device, callback) { +function deviceUpdatingHandler(device, oldDevice, callback) { return callback(null, device); } diff --git a/lib/bindings/HTTPBinding.js b/lib/bindings/HTTPBinding.js index 7055db0a..06ac8a3d 100644 --- a/lib/bindings/HTTPBinding.js +++ b/lib/bindings/HTTPBinding.js @@ -546,10 +546,12 @@ function deviceProvisioningHandler(device, callback) { * * @param {Object} device Device object containing all the information about the updated device. */ -function deviceUpdatingHandler(device, callback) { - config.getLogger().debug(context, 'httpbinding.deviceUpdatingHandler device %j', device); +function deviceUpdatingHandler(newDevice, oldDevice, callback) { + config + .getLogger() + .debug(context, 'httpbinding.deviceUpdatingHandler newDevice %j oldDevice %j', newDevice, oldDevice); let group = {}; - iotAgentLib.getConfigurationSilently(config.getConfig().iota.defaultResource || '', device.apikey, function ( + iotAgentLib.getConfigurationSilently(config.getConfig().iota.defaultResource || '', oldDevice.apikey, function ( error, foundGroup ) { @@ -557,7 +559,7 @@ function deviceUpdatingHandler(device, callback) { group = foundGroup; } config.getLogger().debug(context, 'httpbinding.deviceUpdatingHandler group %j', group); - setPollingAndDefaultTransport(device, group, callback); + setPollingAndDefaultTransport(newDevice, group, callback); }); } diff --git a/lib/bindings/MQTTBinding.js b/lib/bindings/MQTTBinding.js index d0361ba6..e20b2f50 100644 --- a/lib/bindings/MQTTBinding.js +++ b/lib/bindings/MQTTBinding.js @@ -345,7 +345,7 @@ function deviceProvisioningHandler(device, callback) { * * @param {Object} device Device object containing all the information about the provisioned device. */ -function deviceUpdatingHandler(device, callback) { +function deviceUpdatingHandler(device, oldDevice, callback) { callback(null, device); } diff --git a/lib/iotagent-json.js b/lib/iotagent-json.js index 3d66dcab..ad54da97 100644 --- a/lib/iotagent-json.js +++ b/lib/iotagent-json.js @@ -101,6 +101,7 @@ function updateHandler(id, type, attributes, service, subservice, callback) { * @param {Object} device Device provisioning information. */ function deviceProvisioningHandler(device, callback) { + config.getLogger().debug(context, 'deviceProvisioningHandler for device %j', device); transportSelector.applyFunctionFromBinding([device], 'deviceProvisioningHandler', null, function (error, devices) { if (error) { callback(error); @@ -111,13 +112,18 @@ function deviceProvisioningHandler(device, callback) { } /** - * Calls all the device updating handlers for each transport protocol binding whenever a new device is updated + * Calls all the device updating handlers for each transport protocol binding whenever a device is updated * in the Agent. * * @param {Object} device Device updating information. */ -function deviceUpdatingHandler(device, callback) { - transportSelector.applyFunctionFromBinding([device], 'deviceUpdatingHandler', null, function (error, devices) { +function deviceUpdatingHandler(newDevice, oldDevice, callback) { + config.getLogger().debug(context, 'deviceUpdatingHandler for newDevice %j oldDevice %j', newDevice, oldDevice); + // Maybe get apikey from group ? + transportSelector.applyFunctionFromBinding([newDevice, oldDevice], 'deviceUpdatingHandler', null, function ( + error, + devices + ) { if (error) { callback(error); } else {