<commit_before>var uuid = require("hap-nodejs").uuid;
var Accessory = require("hap-nodejs").Accessory;
var Service = require("hap-nodejs").Service;
var Characteristic = require("hap-nodejs").Characteristic;

'use strict';

module.exports = {
  PlatformAccessory: PlatformAccessory
}

function PlatformAccessory(displayName, UUID, category) {
  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.category = category || Accessory.Categories.OTHER;
  this.services = [];
  this.reachable = false;
  this.context = {};

  this._associatedPlugin;
  this._associatedPlatform;
  this._associatedHAPAccessory;

  this
    .addService(Service.AccessoryInformation)
    .setCharacteristic(Characteristic.Name, displayName)
    .setCharacteristic(Characteristic.Manufacturer, "Default-Manufacturer")
    .setCharacteristic(Characteristic.Model, "Default-Model")
    .setCharacteristic(Characteristic.SerialNumber, "Default-SerialNumber");
}

PlatformAccessory.prototype.addService = function(service) {
  // service might be a constructor like `Service.AccessoryInformation` instead of an instance
  // of Service. Coerce if necessary.
  if (typeof service === 'function')
    service = new (Function.prototype.bind.apply(service, arguments));
  
  // check for UUID+subtype conflict
  for (var index in this.services) {
    var existing = this.services[index];
    if (existing.UUID === service.UUID) {
      // OK we have two Services with the same UUID. Check that each defines a `subtype` property and that each is unique.
      if (!service.subtype)
        throw new Error("Cannot add a Service with the same UUID '" + existing.UUID + "' as another Service in this Accessory without also defining a unique 'subtype' property.");
      
      if (service.subtype.toString() === existing.subtype.toString())
        throw new Error("Cannot add a Service with the same UUID '" + existing.UUID + "' and subtype '" + existing.subtype + "' as another Service in this Accessory.");
    }
  }

  this.services.push(service);

  if (this._associatedHAPAccessory) {
    this._associatedHAPAccessory.addService(service);
  }
  return service;
}

/**
 * searchs for a Service in the services collection and returns the first Service object that matches.
 * If multiple services of the same type are present in one accessory, use getServiceByUUIDAndSubType instead.
 * @param {ServiceConstructor|string} name
 * @returns Service
 */
PlatformAccessory.prototype.getService = function(name) {
  for (var index in this.services) {
    var service = this.services[index];
    
    if (typeof name === 'string' && (service.displayName === name || service.name === name))
      return service;
    else if (typeof name === 'function' && ((service instanceof name) || (name.UUID === service.UUID)))
      return service;
  }
}

/**
 * searchs for a Service in the services collection and returns the first Service object that matches.
 * If multiple services of the same type are present in one accessory, use getServiceByUUIDAndSubType instead.
 * @param {string} UUID Can be an UUID, a service.displayName, or a constructor of a Service
 * @param {string} subtype A subtype string to match
 * @returns Service
 */
PlatformAccessory.prototype.getServiceByUUIDAndSubType = function(UUID, subtype) {
  for (var index in this.services) {
    var service = this.services[index];
    
    if (typeof UUID === 'string' && (service.displayName === UUID || service.name === UUID) && service.subtype === subtype )
      return service;
    else if (typeof name === 'function' && ((service instanceof name) || (name.UUID === service.UUID)) && service.subtype === subtype)
      return service;
  }
}


PlatformAccessory.prototype.updateReachability = function(reachable) {
  this.reachable = reachable;

  if (this._associatedHAPAccessory) {
    this._associatedHAPAccessory.updateReachability(reachable);
  }
}

PlatformAccessory.prototype._prepareAssociatedHAPAccessory = function () {
  this._associatedHAPAccessory = new Accessory(this.displayName, this.UUID);
  this._associatedHAPAccessory._sideloadServices(this.services);
  this._associatedHAPAccessory.reachable = this.reachable;
}

PlatformAccessory.prototype._dictionaryPresentation = function() {
  var accessory = {};

  accessory.plugin = this._associatedPlugin;
  accessory.platform = this._associatedPlatform;
  accessory.displayName = this.displayName;<commit_msg>Update platformAccessory.js<commit_after>var uuid = require("hap-nodejs").uuid;
var Accessory = require("hap-nodejs").Accessory;
var Service = require("hap-nodejs").Service;
var Characteristic = require("hap-nodejs").Characteristic;

'use strict';

module.exports = {
  PlatformAccessory: PlatformAccessory
}

function PlatformAccessory(displayName, UUID, category) {
  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.category = category || Accessory.Categories.OTHER;
  this.services = [];
  this.reachable = false;
  this.context = {};

  this._associatedPlugin;
  this._associatedPlatform;
  this._associatedHAPAccessory;

  this
    .addService(Service.AccessoryInformation)
    .setCharacteristic(Characteristic.Name, displayName)
    .setCharacteristic(Characteristic.Manufacturer, "Default-Manufacturer")
    .setCharacteristic(Characteristic.Model, "Default-Model")
    .setCharacteristic(Characteristic.SerialNumber, "Default-SerialNumber");
}

PlatformAccessory.prototype.addService = function(service) {
  // service might be a constructor like `Service.AccessoryInformation` instead of an instance
  // of Service. Coerce if necessary.
  if (typeof service === 'function')
    service = new (Function.prototype.bind.apply(service, arguments));
  
  // check for UUID+subtype conflict
  for (var index in this.services) {
    var existing = this.services[index];
    if (existing.UUID === service.UUID) {
      // OK we have two Services with the same UUID. Check that each defines a `subtype` property and that each is unique.
      if (!service.subtype)
        throw new Error("Cannot add a Service with the same UUID '" + existing.UUID + "' as another Service in this Accessory without also defining a unique 'subtype' property.");
      
      if (service.subtype.toString() === existing.subtype.toString())
        throw new Error("Cannot add a Service with the same UUID '" + existing.UUID + "' and subtype '" + existing.subtype + "' as another Service in this Accessory.");
    }
  }

  this.services.push(service);

  if (this._associatedHAPAccessory) {
    this._associatedHAPAccessory.addService(service);
  }
  return service;
}

/**
 * searchs for a Service in the services collection and returns the first Service object that matches.
 * If multiple services of the same type are present in one accessory, use getServiceByUUIDAndSubType instead.
 * @param {ServiceConstructor|string} name
 * @returns Service
 */
PlatformAccessory.prototype.getService = function(name) {
  for (var index in this.services) {
    var service = this.services[index];
    
    if (typeof name === 'string' && (service.displayName === name || service.name === name))
      return service;
    else if (typeof name === 'function' && ((service instanceof name) || (name.UUID === service.UUID)))
      return service;
  }
}

/**
 * searchs for a Service in the services collection and returns the first Service object that matches.
 * If multiple services of the same type are present in one accessory, use getServiceByUUIDAndSubType instead.
 * @param {string} UUID Can be an UUID, a service.displayName, or a constructor of a Service
 * @param {string} subtype A subtype string to match
 * @returns Service
 */
PlatformAccessory.prototype.getServiceByUUIDAndSubType = function(UUID, subtype) {
  for (var index in this.services) {
    var service = this.services[index];
    
    if (typeof UUID === 'string' && (service.displayName === UUID || service.name === UUID) && service.subtype === subtype )
      return service;
    else if (typeof name === 'function' && ((service instanceof name) || (UUID.UUID === service.UUID)) && service.subtype === subtype)
      return service;
  }
}


PlatformAccessory.prototype.updateReachability = function(reachable) {
  this.reachable = reachable;

  if (this._associatedHAPAccessory) {
    this._associatedHAPAccessory.updateReachability(reachable);
  }
}

PlatformAccessory.prototype._prepareAssociatedHAPAccessory = function () {
  this._associatedHAPAccessory = new Accessory(this.displayName, this.UUID);
  this._associatedHAPAccessory._sideloadServices(this.services);
  this._associatedHAPAccessory.reachable = this.reachable;
}

PlatformAccessory.prototype._dictionaryPresentation = function() {
  var accessory = {};

  accessory.plugin = this._associatedPlugin;
  accessory.platform = this._associatedPlatform;
  accessory.displayName = this.displayName;
{'fraction_non_alphanumeric': 0.11056690287619841, 'fraction_numerical': 0.0, 'mean_word_length': 4.32870627429206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4086911', 'n_tokens_mistral': 2668, 'n_tokens_neox': 2641, 'n_words': 806}