Skip to content

Commit

Permalink
Add handler for when a device has been saved. (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstegeman committed Oct 30, 2019
1 parent 76a2186 commit 77939d3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
21 changes: 19 additions & 2 deletions lib/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Adapter {
}

/**
* @method deviceAdded
* @method handleDeviceAdded
*
* Called to indicate that a device is now being managed by this adapter.
*/
Expand All @@ -85,7 +85,7 @@ class Adapter {
}

/**
* @method deviceRemoved
* @method handleDeviceRemoved
*
* Called to indicate that a device is no longer managed by this adapter.
*/
Expand All @@ -94,6 +94,23 @@ class Adapter {
this.manager.handleDeviceRemoved(device);
}

/**
* @method handleDeviceSaved
*
* Called to indicate that the user has saved a device to their gateway. This
* is also called when the adapter starts up for every device which has
* already been saved.
*
* This can be used for keeping track of what devices have previously been
* discovered, such that the adapter can rebuild those, clean up old nodes,
* etc.
*
* @param {string} deviceId - ID of the device
* @param {object} device - the saved device description
*/
handleDeviceSaved(_deviceId, _device) {
}

// eslint-disable-next-line
startPairing(timeoutSeconds) {
console.log('Adapter:', this.name, 'id', this.id, 'pairing started');
Expand Down
3 changes: 3 additions & 0 deletions lib/addon-manager-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ class AddonManagerProxy extends EventEmitter {
adapter.unpairDevice(msg.data.deviceId);
return;

case MessageType.DEVICE_SAVED_NOTIFICATION:
adapter.handleDeviceSaved(msg.data.deviceId, msg.data.device);
return;
}

// All messages from here on are assumed to require a valid deviceId.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"devDependencies": {
"babel-eslint": "^10.0.3",
"eslint": "^6.4.0"
"eslint": "^6.6.0"
},
"files": [
"LICENSE",
Expand Down
2 changes: 1 addition & 1 deletion schema

0 comments on commit 77939d3

Please sign in to comment.