lib/Accessory.js
function Accessory(displayName, UUID) {

  if (!displayName) throw new Error("Accessories must be created with a non-empty displayName.");
  if (!UUID) throw new Error("Accessories must be created with a valid UUID.");
  if (!uuid.isValid(UUID)) throw new Error("UUID '" + UUID + "' is not a valid UUID. Try using the provided 'generateUUID' function to create a valid UUID from any arbitrary string, like a serial number.");

  this.displayName = displayName;
  this.UUID = UUID;
  this.aid = null; // assigned by us in assignIDs() or by a Bridge
  this._isBridge = false; // true if we are a Bridge (creating a new instance of the Bridge subclass sets this to true)
  this.bridged = false; // true if we are hosted "behind" a Bridge Accessory
  this.bridgedAccessories = []; // If we are a Bridge, these are the Accessories we are bridging
  this.reachable = true;
  this.category = Accessory.Categories.OTHER;
  this.services = []; // of Service
  this.cameraSource = null;
  this.shouldPurgeUnusedIDs = true; // Purge unused ids by default

  // create our initial "Accessory Information" Service that all Accessories are expected to have
  this
    .addService(Service.AccessoryInformation)
    .setCharacteristic(Characteristic.Name, displayName)
    .setCharacteristic(Characteristic.Manufacturer, "Default-Manufacturer")
    .setCharacteristic(Characteristic.Model, "Default-Model")
    .setCharacteristic(Characteristic.SerialNumber, "Default-SerialNumber")
    .setCharacteristic(Characteristic.FirmwareRevision, "1.0");

  // sign up for when iOS attempts to "set" the Identify characteristic - this means a paired device wishes
  // for us to identify ourselves (as opposed to an unpaired device - that case is handled by HAPServer 'identify' event)
  this
    .getService(Service.AccessoryInformation)
    .getCharacteristic(Characteristic.Identify)
    .on('set', function(value, callback) {
      if (value) {
        var paired = true;
        this._identificationRequest(paired, callback);
      }
    }.bind(this));
}
function Accessory(displayName, UUID) {

  if (!displayName) throw new Error("Accessories must be created with a non-empty displayName.");
  if (!UUID) throw new Error("Accessories must be created with a valid UUID.");
  if (!uuid.isValid(UUID)) throw new Error("UUID '" + UUID + "' is not a valid UUID. Try using the provided 'generateUUID' function to create a valid UUID from any arbitrary string, like a serial number.");

  this.displayName = displayName;
  this.UUID = UUID;
  this.aid = null; // assigned by us in assignIDs() or by a Bridge
  this._isBridge = false; // true if we are a Bridge (creating a new instance of the Bridge subclass sets this to true)
  this.bridged = false; // true if we are hosted "behind" a Bridge Accessory
  this.bridgedAccessories = []; // If we are a Bridge, these are the Accessories we are bridging
  this.reachable = true;
  this.category = Accessory.Categories.OTHER;
  this.services = []; // of Service
  this.cameraSource = null;
  this.shouldPurgeUnusedIDs = true; // Purge unused ids by default

  // create our initial "Accessory Information" Service that all Accessories are expected to have
  this
    .addService(Service.AccessoryInformation)
    .setCharacteristic(Characteristic.Name, displayName)
    .setCharacteristic(Characteristic.Manufacturer, "Default-Manufacturer")
    .setCharacteristic(Characteristic.Model, "Default-Model")
    .setCharacteristic(Characteristic.SerialNumber, "Default-SerialNumber")
    .setCharacteristic(Characteristic.FirmwareRevision, "1.0");

  // sign up for when iOS attempts to "set" the Identify characteristic - this means a paired device wishes
  // for us to identify ourselves (as opposed to an unpaired device - that case is handled by HAPServer 'identify' event)
  this
    .getService(Service.AccessoryInformation)
    .getCharacteristic(Characteristic.Identify)
    .on('set', function(value, callback) {
      if (value) {
        var paired = true;
        this._identificationRequest(paired, callback);
      }
    }.bind(this));
}
function Accessory ( displayName , UUID ) { if ( ! displayName ) throw new Error ( "Accessories must be created with a non-empty displayName." ) ; if ( ! UUID ) throw new Error ( "Accessories must be created with a valid UUID." ) ; if ( ! uuid . isValid ( UUID ) ) throw new Error ( "UUID '" + UUID + "' is not a valid UUID. Try using the provided 'generateUUID' function to create a valid UUID from any arbitrary string, like a serial number." ) ; this . displayName = displayName ; this . UUID = UUID ; this . aid = null ; // assigned by us in assignIDs() or by a Bridge this . _isBridge = false ; // true if we are a Bridge (creating a new instance of the Bridge subclass sets this to true) this . bridged = false ; // true if we are hosted "behind" a Bridge Accessory this . bridgedAccessories = [ ] ; // If we are a Bridge, these are the Accessories we are bridging this . reachable = true ; this . category = Accessory . Categories . OTHER ; this . services = [ ] ; // of Service this . cameraSource = null ; this . shouldPurgeUnusedIDs = true ; // Purge unused ids by default // create our initial "Accessory Information" Service that all Accessories are expected to have this . addService ( Service . AccessoryInformation ) . setCharacteristic ( Characteristic . Name , displayName ) . setCharacteristic ( Characteristic . Manufacturer , "Default-Manufacturer" ) . setCharacteristic ( Characteristic . Model , "Default-Model" ) . setCharacteristic ( Characteristic . SerialNumber , "Default-SerialNumber" ) . setCharacteristic ( Characteristic . FirmwareRevision , "1.0" ) ; // sign up for when iOS attempts to "set" the Identify characteristic - this means a paired device wishes // for us to identify ourselves (as opposed to an unpaired device - that case is handled by HAPServer 'identify' event) this . getService ( Service . AccessoryInformation ) . getCharacteristic ( Characteristic . Identify ) . on ( 'set' , function ( value , callback ) { if ( value ) { var paired = true ; this . _identificationRequest ( paired , callback ) ; } } . bind ( this ) ) ; }
Accessory is a virtual HomeKit device. It can publish an associated HAP server for iOS devices to communicate
with - or it can run behind another "Bridge" Accessory server.

Bridged Accessories in this implementation must have a UUID that is unique among all other Accessories that
are hosted by the Bridge. This UUID must be "stable" and unchanging, even when the server is restarted. This
is required so that the Bridge can provide consistent "Accessory IDs" (aid) and "Instance IDs" (iid) for all
Accessories, Services, and Characteristics for iOS clients to reference later.

@event 'identify' => function(paired, callback(err)) { }
Emitted when an iOS device wishes for this Accessory to identify itself. If `paired` is false, then
this device is currently browsing for Accessories in the system-provided "Add Accessory" screen. If
`paired` is true, then this is a device that has already paired with us. Note that if `paired` is true,
listening for this event is a shortcut for the underlying mechanism of setting the `Identify` Characteristic:
`getService(Service.AccessoryInformation).getCharacteristic(Characteristic.Identify).on('set', ...)`
You must call the callback for identification to be successful.

@event 'service-characteristic-change' => function({service, characteristic, oldValue, newValue, context}) { }
Emitted after a change in the value of one of the provided Service's Characteristics.
Accessory is a virtual HomeKit device . It can publish an associated HAP server for iOS devices to communicate with - or it can run behind another Bridge Accessory server .