Credentials Login

"template": "login_credentials"

This pair template shows a username & password view where the user can enter credentials.

/drivers/<driver_id>/driver.js

class MyDriver extends Homey.Driver {
  async onPair(session) {
    let username = '';
    let password = '';

    session.setHandler('login', async (data) => {
      username = data.username;
      password = data.password;

      const credentialsAreValid = await MyAPI.testCredentials({
        username,
        password,
      });

      if (typeof credentialsAreValid !== 'boolean') {
        throw new Error('Invalid Response');
      }

      return credentialsAreValid;
    });

    session.setHandler('list_devices', async (data) => {
      const api = await MyAPI.login({ username, password });
      const myDevices = await api.getDevices();

      const devices = myDevices.map((myDevice) => {
        return {
          name: myDevice.name,
          data: {
            id: myDevice.id,
          },
          settings: {
            // Store username & password in settings
            // so the user can change them later
            username,
            password,
          },
        };
      });

      return devices;
    });
  }
}

Options

Key Type Default Description
logo string "" A path to an image for a logo
usernameLabel i18n-object "E-mail address"
usernamePlaceholder i18n-object "john@doe.com"
passwordLabel i18n-object "Enter pincode:"
passwordPlaceholder i18n-object "Password"