WifiDriver
Library that extends HomeyDriver
and HomeyDevice
to provide a set of functionality that is commonly used in Homey Apps that support devices over WiFi.
Note: this library is still under development, use at your own risk.
Installation
cd /path/to/com.your.homeyapp/
npm install --save https://github.com/athombv/node-homey-wifidriver
cd node_modules/homey-wifidriver
npm install
Docs
See https://athombv.github.io/node-homey-wifidriver
Example
File: /drivers/mydriver/driver.js
const OAuth2Driver = OAuth2Driver;const ExampleAPI = ; const oauth2ClientConfig = url: `https://api.example.com/authorize?response_type=code&client_id=&redirect_uri=https://callback.athom.com/oauth2/callback/` tokenEndpoint: 'https://api.example.com/token' key: HomeyenvAPI_CLIENT_ID secret: HomeyenvAPI_CLIENT_SECRET allowMultipleAccounts: false; // Which extends WifiDriver { // This will override onPair() to handle OAuth2 pairing super; } /** * This method will be called if a oauth2ClientConfig is provided onInit. The data object contains * an authenticated OAuth2Account instance which will be destroyed automatically after pairing * has ended. */ { // Create temporary API client with temporary account const exampleApiClient = oauth2Account: dataoauth2Account ; // Return promise that fetches devices from account return exampleApiClient }
File: /drivers/mydriver/device.js
const OAuth2Device = OAuth2Device; const backOffStrategy = initialDelay: 10000 // 10 seconds maxDelay: 1000 * 60 * 60 // 1 hour maxTries: 10 // Optional, max backoff tries, if not provided it will not end until reset onBackOffReady: {} // Optional, if provided this method will be called on each backoff, else it will default to this.onInit() onBackOffFailed: {} // Optional, this method will be called when backoff failed; maxTries was exceeded // Which extends WifiDevice { super; // Create API client with OAuth2Account thisexampleApiClient = oauth2Account: this // OAuth2Account instance that handles fetching and refreshing access tokens ; // Method that will create an interval this; // To stop polling this; } { // Clean up registered polling intervals super; }