Lock Mechanism

UUID: 00000045-0000-1000-8000-0026BB765291

Required Characteristics

Optional Characteristics

Example

Note

The example below is automatically generated and may not be a complete example of what is required to create a working "Lock Mechanism" Homebridge plugin.
// Example Lock Mechanism Plugin

module.exports = (api) => {
  api.registerAccessory('ExampleLockMechanismPlugin', ExampleLockMechanismAccessory);
};

class ExampleLockMechanismAccessory {

  constructor(log, config, api) {
      this.log = log;
      this.config = config;
      this.api = api;

      this.Service = this.api.hap.Service;
      this.Characteristic = this.api.hap.Characteristic;

      // extract name from config
      this.name = config.name;

      // create a new Lock Mechanism service
      this.service = new this.Service(this.Service.LockMechanism);

      // create handlers for required characteristics
      this.service.getCharacteristic(this.Characteristic.LockCurrentState)
        .on('get', this.handleLockCurrentStateGet.bind(this));

      this.service.getCharacteristic(this.Characteristic.LockTargetState)
        .on('get', this.handleLockTargetStateGet.bind(this))
        .on('set', this.handleLockTargetStateSet.bind(this));

  }

  /**
   * Handle requests to get the current value of the "Lock Current State" characteristic
   */
  handleLockCurrentStateGet(callback) {
    this.log.debug('Triggered GET LockCurrentState');

    // set this to a valid value for LockCurrentState
    const currentValue = 1;

    callback(null, currentValue);
  }


  /**
   * Handle requests to get the current value of the "Lock Target State" characteristic
   */
  handleLockTargetStateGet(callback) {
    this.log.debug('Triggered GET LockTargetState');

    // set this to a valid value for LockTargetState
    const currentValue = 1;

    callback(null, currentValue);
  }

  /**
   * Handle requests to set the "Lock Target State" characteristic
   */
  handleLockTargetStateSet(value, callback) {
    this.log.debug('Triggered SET LockTargetState:' value);

    callback(null);
  }

}