Constructor
new WifiDevice()
Example
const WifiDevice = require('homey-wifidriver').WifiDevice;
class myDevice extends WifiDevice {
onInit() {
// Create initialization back off strategy
if(this.backOffStrategy === 'undefined') {
this.registerBackOffStrategy({
initialDelay: 10000, // 10 seconds
maxDelay: 1000 * 60 * 60, // 1 hour
maxTries: 10, // Optional, max back off tries, if not provided it will not end until reset
onBackOffReady: this.onInit.bind(this), // Optional, if provided this method will be called on each back off
onBackOffFailed: (() => {}), // Optional, this method will be called when back off failed; maxTries was exceeded
})
}
// Method that will create an interval
this.registerPollInterval({
id: 'status',
fn: this.exampleApiClient.getStatus.bind(this.exampleApiClient),
interval: 30000,
});
// To stop polling
this.deregisterPollInterval('status');
if(initializationSuccess === true) {
this.backOffStrategy.abort()
} else {
this.backOffStrategy.backoff()
}
}
onDeleted() {
// Clean up registered polling intervals
super.onDeleted();
}
}
Extends
- Homey.Device
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 |
onDeleted()
This method will be called when the device has been deleted, it makes sure the client is properly destroyed and left over settings are removed.
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
|
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
|