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.

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: Homey

The Homey instance of this driver

Type

manifest

manifest: any

The driver's manifest (app.json entry)

Type

  • any

Methods

getDevice

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

Device

getDevices

getDevices(): Array.<Device>

Get an Array with all Device instances

Returns

Devices

Array.<Device>

getDiscoveryStrategy

getDiscoveryStrategy(): DiscoveryStrategy

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

Returns

onInit

(async) onInit()

This method is called when the driver is inited.

onMapDeviceClass

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

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

onPairListDevices

(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

Promise.<Array.<any>>

ready

ready(): Promise.<void>

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

Returns

promise that is resolved when the Drivers Manager is ready

Promise.<void>