Constructor
new WebAPIDevice()
Example
const WebAPIDevice = require('homey-wifidriver').WebAPIDevice;
class myDevice extends WebAPIDevice {
async onInit(){
await super.onInit({
apiBaseUrl: 'http://www.example-api.com/',
throttle: 500, // 500ms between api calls
rateLimit: {
max: 5,
per: 60000, // maximum of 5 requests per minute, all exceeding calls will be queued
}
}).catch(err => this.error(err));
this.setDefaultHeaders({
Authorization: 'Bearer 123456789'
});
this.apiCallGet({command: 'testRequest'})
.then(res => {
console.log(res);
})
}
}
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 abort all outstanding api calls.
- Overrides:
(async) onInit(options) → {Promise}
This method needs to be called from a device.onInit(), it will create a PromiseQueue that will be used for queueing, throttling and rate limiting api calls.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
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: