Constructor
new OAuth2Device()
Example
const OAuth2Device = require('homey-wifidriver').OAuth2Device;
class myDevice extends OAuth2Device {
sync onInit() {
await super.onInit()
.catch(err => this.error(err));
// this.oauth2Account contains authenticated OAuth2Account instance
// all api calls will be injected with 'Authorization: Bearer <access_token>' from OAuth2Account instance
this.apiGetCall({uri: 'http://example.api.com/status'})
.then(res => {
this.log(res);
});
}
onDeleted() {
super.onDeleted();
}
}
Extends
Methods
deregisterPollInterval(id)
Method that clears the poll interval and removes the registered interval from the list.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | poll interval identifier |
- Inherited From:
onDeleted()
Method that will be called when device is deleted, it will delete its OAuth2Account from the client. TODO when multiple OAuth2Accounts are allowed do not directly remove, but check if other devices use this account as well.
- Overrides:
(async) onInit(options) → {Promise}
Method that initializes device with OAuth2Account instance and authenticated API call methods.
Parameters:
Name | Type | Description |
---|---|---|
options |
- Overrides:
Returns:
- Type
- Promise
registerBackOffStrategy(options) → {BackOffStrategy|Error}
Method that creates and returns a back off strategy (Fibonacci).
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Specification for initialization backoff strategy Properties
|
- Inherited From:
Returns:
backOffStrategy - Back off strategy instance
- Type
- BackOffStrategy | Error
registerPollInterval(options)
Method that adds a poll interval to the list, and starts polling on the provided interval.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
- Inherited From:
webAPIErrorHandler(err)
Overridable method that will be called as middleware upon a failed API request.
Parameters:
Name | Type | Description |
---|---|---|
err |