Driver

The Driver class manages all Device instances, which represent all paired devices. This class should be extended and exported from driver.js. Methods prefixed with on are meant to be overriden. It is not allowed to overwrite the constructor.

Table of Contents

Library:
Example

/drivers/my_driver/driver.js

const Homey = require('homey');

class MyDriver extends Homey.Driver {
  async onInit() {
    this.log('MyDriver has been initialized');
  }
}

module.exports = MyDriver;

Properties

homey :Homey

The Homey instance of this driver

Type:

manifest :object

The driver's manifest (app.json entry)

Type:
  • object

Methods

getDevice(deviceData) → {Device}

Get a Device instance by its deviceData object.

Parameters:
Name Type Description
deviceData object

Unique Device object as provided during pairing

Returns:
Type:
Device

Device

getDevices() → {Array.<Device>}

Get an Array with all Device instances

Returns:
Type:
Array.<Device>

Devices

getDiscoveryStrategy() → {DiscoveryStrategy}

Get the driver's discovery strategy when defined in the manifest

Returns:
Type:
DiscoveryStrategy

(async) onInit()

This method is called when the driver is inited.

onMapDeviceClass(device)

When this method exists, it will be called prior to initing the device instance. Return a class that extends Device.

Parameters:
Name Type Description
device Device

A temporary Device instance to check certain properties before deciding which class the device should use. This class will exist for a single tick, and does not support async methods.

Example
class MyDriver extends Homey.Driver {

  onMapDeviceClass( device ) {
    if( device.hasCapability('dim') ) {
      return MyDeviceDim;
    } else {
      return MyDevice;
    }
  }
}

onPair(session)

This method is called when a pair session starts.

Parameters:
Name Type Description
session PairSession

Bi-directional socket for communication with the front-end

(async) onPairListDevices() → {Promise.<Array.<any>>}

This method is called when no custom onPair() method has been defined, and the default is being used. Simple drivers should override this method to provide a list of devices ready to be paired.

Returns:
Type:
Promise.<Array.<any>>

ready() → {Promise.<void>}

Returns a promise which is resolved when the Driver is ready (Driver#onInit has been run).

Returns:
Type:
Promise.<void>

promise that is resolved when the Drivers Manager is ready