Pair a device with user
On Grandeur, a device falls under the ownership of the project's administrator. The project's API Key delegates the device pairing authority to the SDK which the user uses to pair with the device. Pairing a device makes it live on Grandeur and the user gets delegated access to the device's data. But a user cannot delete or modify a device's inherent data because it's not within its scope.A user can pair with any number of devices but a device can be paired with at the most one user.
The device entity, in the end, defines two things:
-
What kind of data a hardware device can access in your namespace and
-
Which hardware devices a user can control.
This is a security essential because consider the case that anybody gets access to control of your smart locks, or your neighbours get to control the air conditioner settings in your house. That's what this entity has been designed for. A user can only interact with devices that are paired with it. When you pair a device with a user account, an access token is generated for the device. This token is what the device uses to connect to Grandeur. The pairing feature is similar to claiming ownership over a device. When you send us a pairing request, we first verify that the device isn't paired to another account.
Use of pair method has been illustrated in the example below
// Submit request to the server
device.pair().then((res) => {
// Got the response
switch(res.code) {
case "DEVICE-PAIRED":
// Transfer the token to the device
console.log(res);
}
})
Just like pairing you can also unpair your device. It allows you to unpair a device from a user account. It simply declares that the user account no longer owns the device. In other words, it makes the device available for other users to claim.
Use of unpairDevice method has been illustrated in the example below
// Submit request to the server
device.unpair().then((res) => {
// Got the response
switch(res.code) {
case "DEVICE-UNPAIRED":
// Device got unpaired with the user account
}
})