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 {
  async onPair(session) {
    const devices = [
      {
        name: 'My Device',
        data: {
          id: 'abcd',
        },
      },
    ];

    session.setHandler('list_devices', async function (data) {
      // emit when devices are still being searched
      session.emit('list_devices', devices);

      // return devices when searching is done
      return devices;

      // when no devices are found, return an empty array
      // return [];

      // or throw an Error to show that instead
      // throw new Error('Something bad has occured!');
    });
  }

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

    return devices;
  }
}

Options

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