GladysProject/Gladys

View on GitHub
server/services/homekit/lib/newPinCode.js

Summary

Maintainability
A
0 mins
Test Coverage
/**
 * @description Generate new pincode.
 * @returns {Promise} Resolving with new pin code.
 * @example
 * newPinCode()
 */
async function newPinCode() {
  const rd = () => Math.floor(Math.random() * 10);
  const pincode = `${rd()}${rd()}${rd()}-${rd()}${rd()}-${rd()}${rd()}${rd()}`;

  await this.gladys.variable.setValue('HOMEKIT_PIN_CODE', pincode, this.serviceId);

  return pincode;
}

module.exports = {
  newPinCode,
};