Class: OAuth2Device

OAuth2Device()

The OAuth2Device class exposes the getOAuth2Account method.

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
Name Type Attributes Default Description
onBackOffReady function

Function will be called on each back off tick

onBackOffFailed function <optional>

Function will be called when back off failed (maxTries exceeded)

randomisationFactor number <optional>
0

Randomize the interval (0 - 1)

initialDelay number <optional>
10000

After first failed init wait this long (ms)

maxDelay number <optional>
300000

Max length of time between init retries (ms)

maxTries number <optional>
infinite

Max number of initialization retries

startImmediately boolean <optional>
false

Backoff called on creation

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
Name Type Description
id string

Custom id of poll interval

fn function

Method that will be called when polling

interval number

Time in ms between polling intervals

Inherited From:

webAPIErrorHandler(err)

Overridable method that will be called as middleware upon a failed API request.

Parameters:
Name Type Description
err