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 {

    onPair( socket ) {
      let username = '';
      let password = '';

      socket.on('login', ( data, callback ) => {
          username = data.username;
          password = data.password;

          MyAPI.testCredentials({ username, password })
            .then(credentialsAreValid => {
              if( credentialsAreValid === true ) {
                callback( null, true );
              } else if( credentialsAreValid === false ) {
                callback( null, false );
              } else {
                throw new Error('Invalid Response');
              }
            })
            .catch(err => {
              callback(err);
            });
      });

      socket.on('list_devices', ( data, callback ) => {

        MyAPI.login({ username, password })
          .then(api => {
            return api.getDevices();
          })
          .then(myDevices => {
            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,
                }
              }
            });
            callback( null, 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"