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;
Instance Properties
homey
homey: Homeymanifest
manifest: anyThe driver's manifest (app.json entry)
Type
- any
Instance Methods
getDevice
getDevice(deviceData): DeviceGet 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>getDiscoveryStrategy
getDiscoveryStrategy(): DiscoveryStrategyGet 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
onUninit
(async) onUninit()This method is called when the driver is destroyed.
ready
(async) 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