Devices List

"template": "list_devices"

This view will show a list of selectable devices to the user, and allows the user to rename the device as well.

Devices are automatically filtered and updated, based on their data property.

Example

/app.json

{
  "id": "com.athom.testsuite",
  "drivers": [
    {
      "id": "my_driver",
      // ...
      "pair": [
        {
          "id": "list_devices",
          "template": "list_devices",
          "navigation": {
            "next": "add_devices"
          },
          "options": {
            "singular": false
          }
        },
        {
          "id": "add_devices",
          "template": "add_devices"
        }
      ]
    }
  ]
}

/drivers/<driver_id>/driver.js

const Homey = require('homey');

class MyDriver extends Homey.Driver {

  onPair( socket ) {
    const devices = [
      {
        'name': 'My Device',
        'data': {
          'id': 'abcd',
        }
      }
    ]

    socket.on('list_devices', function( data, callback ) {
      // emit when devices are still being searched
      socket.emit('list_devices', devices );

      // fire the callback when searching is done
      callback( null, devices );

      // when no devices are found, return an empty array
      // callback( null, [] );

      // or fire a callback with Error to show that instead
      // callback( new Error('Something bad has occured!') );
    });
  }

  // alternatively, use the shorthand method
  onPairListDevices( data, callback ) {
    const devices = [
      {
        'name': 'My Device',
        'data': {
          'id': 'abcd',
        }
      }
    ]

    callback( null, devices );
  }
}

Options

Key Type Default Description
singular boolean false Only allow a single device to be selected