Skip to content

Commit

Permalink
uses previous device in device update handler
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed May 22, 2024
1 parent 84af6f9 commit baae52f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/bindings/AMQPBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/bindings/ARGOBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
10 changes: 6 additions & 4 deletions lib/bindings/HTTPBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,18 +546,20 @@ 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
) {
if (!error) {
group = foundGroup;
}
config.getLogger().debug(context, 'httpbinding.deviceUpdatingHandler group %j', group);
setPollingAndDefaultTransport(device, group, callback);
setPollingAndDefaultTransport(newDevice, group, callback);
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/bindings/MQTTBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 9 additions & 3 deletions lib/iotagent-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down

0 comments on commit baae52f

Please sign in to comment.