How to use the hap-nodejs.Characteristic function in hap-nodejs

To help you get started, we’ve selected a few hap-nodejs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nfarina / homebridge / lib / bridgeSetupManager.js View on Github external
minValue: 0,
    maxValue: 1,
    minStep: 1,
    perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
  });
  this.stateCharacteristic.value = 0;
  this.service.addCharacteristic(this.stateCharacteristic);

  this.versionCharacteristic = new Characteristic("Version", "FD9FE4CC-D06F-4FFE-96C6-595D464E1026", {
    format: Characteristic.Formats.STRING,
    perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
  });
  this.versionCharacteristic.value = "1.0";
  this.service.addCharacteristic(this.versionCharacteristic);

  this.controlPointCharacteristic = new Characteristic("Control Point", "5819A4C2-E1B0-4C9D-B761-3EB1AFF43073", {
    format: Characteristic.Formats.DATA,
    perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
  })
  this.controlPointCharacteristic.on('get', function(callback, context) {
    this.handleReadRequest(callback, context);
  }.bind(this));
  this.controlPointCharacteristic.on('set', function(newValue, callback, context) {
    this.handleWriteRequest(newValue, callback, context);
  }.bind(this));

  this.controlPointCharacteristic.value = null;
  this.service.addCharacteristic(this.controlPointCharacteristic);
}
github mrsharpoblunto / it-gets-the-hose-again / web / lib / valve-accessory.js View on Github external
const valve = new hap.Accessory('Water valve', valveUUID);

    valve
        .getService(hap.Service.AccessoryInformation)
        .setCharacteristic(hap.Characteristic.Manufacturer, config.MANUFACTURER)
        .setCharacteristic(hap.Characteristic.Model, config.MODEL)
        .setCharacteristic(hap.Characteristic.SerialNumber, config.SERIAL);

    valve.on('identify', function(paired, cb) {
        valveController.identify();
        cb();
    });

    valve
        .addService(hap.Service.Switch, 'It gets the hose again')
        .getCharacteristic(hap.Characteristic.On)
        .on('set', function(value, cb) {
            valveController.setOpen(!!value, config.HOMEKIT_USER, cb);
        });

    valve
        .getService(hap.Service.Switch)
        .getCharacteristic(hap.Characteristic.On)
        .on('get', function(cb) {
            cb(valveController.getOpen() ? 1 : 0);
        });

    valveController.on('setOpen', function({
        open, source
    }) {
        if (source !== config.HOMEKIT_USER) {
            valve
github paolotremadio / homebridge-automation-chromecast / custom-characteristics.js View on Github external
const DeviceIp = function () {
  const char = new Characteristic('IP Address', DeviceIpUUID);

  char.setProps({
    format: Characteristic.Formats.STRING,
    perms: [Characteristic.Perms.READ],
  });
  char.value = char.getDefaultValue();
  return char;
};
DeviceIp.UUID = DeviceIpUUID;
github nfarina / homebridge / lib / bridgeSetupManager.js View on Github external
function BridgeSetupManager() {
  this.session;

  this.service = new Service(null, "49FB9D4D-0FEA-4BF1-8FA6-E7B18AB86DCE");

  this.stateCharacteristic = new Characteristic("State", "77474A2F-FA98-485E-97BE-4762458774D8", {
    format: Characteristic.Formats.UINT8,
    minValue: 0,
    maxValue: 1,
    minStep: 1,
    perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
  });
  this.stateCharacteristic.value = 0;
  this.service.addCharacteristic(this.stateCharacteristic);

  this.versionCharacteristic = new Characteristic("Version", "FD9FE4CC-D06F-4FFE-96C6-595D464E1026", {
    format: Characteristic.Formats.STRING,
    perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
  });
  this.versionCharacteristic.value = "1.0";
  this.service.addCharacteristic(this.versionCharacteristic);
github paolotremadio / homebridge-automation-chromecast / custom-characteristics.js View on Github external
const DeviceId = function () {
  const char = new Characteristic('ID', DeviceIdUUID);

  char.setProps({
    format: Characteristic.Formats.STRING,
    perms: [Characteristic.Perms.READ],
  });
  char.value = char.getDefaultValue();
  return char;
};
DeviceId.UUID = DeviceIdUUID;
github mrsharpoblunto / it-gets-the-hose-again / web / lib / valve-accessory.js View on Github external
export default function(valveController) {
    const valveUUID = hap.uuid.generate('hap-nodejs:accessories:valve');

    const valve = new hap.Accessory('Water valve', valveUUID);

    valve
        .getService(hap.Service.AccessoryInformation)
        .setCharacteristic(hap.Characteristic.Manufacturer, config.MANUFACTURER)
        .setCharacteristic(hap.Characteristic.Model, config.MODEL)
        .setCharacteristic(hap.Characteristic.SerialNumber, config.SERIAL);

    valve.on('identify', function(paired, cb) {
        valveController.identify();
        cb();
    });

    valve
        .addService(hap.Service.Switch, 'It gets the hose again')
        .getCharacteristic(hap.Characteristic.On)
        .on('set', function(value, cb) {
            valveController.setOpen(!!value, config.HOMEKIT_USER, cb);
        });

    valve
github paolotremadio / homebridge-automation-chromecast / custom-characteristics.js View on Github external
const DeviceType = function () {
  const char = new Characteristic('Type', DeviceTypeUUID);

  char.setProps({
    format: Characteristic.Formats.STRING,
    perms: [Characteristic.Perms.READ],
  });
  char.value = char.getDefaultValue();
  return char;
};
DeviceType.UUID = DeviceTypeUUID;
github nfarina / homebridge / lib / bridgeSetupManager.js View on Github external
function BridgeSetupManager() {
  this.session;

  this.service = new Service(null, "49FB9D4D-0FEA-4BF1-8FA6-E7B18AB86DCE");

  this.stateCharacteristic = new Characteristic("State", "77474A2F-FA98-485E-97BE-4762458774D8", {
    format: Characteristic.Formats.UINT8,
    minValue: 0,
    maxValue: 1,
    minStep: 1,
    perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
  });
  this.stateCharacteristic.value = 0;
  this.service.addCharacteristic(this.stateCharacteristic);

  this.versionCharacteristic = new Characteristic("Version", "FD9FE4CC-D06F-4FFE-96C6-595D464E1026", {
    format: Characteristic.Formats.STRING,
    perms: [Characteristic.Perms.READ, Characteristic.Perms.NOTIFY]
  });
  this.versionCharacteristic.value = "1.0";
  this.service.addCharacteristic(this.versionCharacteristic);

  this.controlPointCharacteristic = new Characteristic("Control Point", "5819A4C2-E1B0-4C9D-B761-3EB1AFF43073", {
    format: Characteristic.Formats.DATA,
    perms: [Characteristic.Perms.READ, Characteristic.Perms.WRITE, Characteristic.Perms.NOTIFY]
  })
  this.controlPointCharacteristic.on('get', function(callback, context) {
    this.handleReadRequest(callback, context);
  }.bind(this));
  this.controlPointCharacteristic.on('set', function(newValue, callback, context) {
    this.handleWriteRequest(newValue, callback, context);
  }.bind(this));
github nfarina / homebridge / lib / platformAccessory.js View on Github external
this.UUID = data.UUID;
  this.category = data.category;
  this.context = data.context;
  this.reachable = false;

  var services = [];
  var servicesMap = {};

  for (var index in data.services) {
    var service = data.services[index];
    var hapService = new Service(service.displayName, service.UUID, service.subtype);

    var characteristics = [];
    for (var cIndex in service.characteristics) {
      var characteristic = service.characteristics[cIndex];
      var hapCharacteristic = new Characteristic(characteristic.displayName, characteristic.UUID, characteristic.props);
      hapCharacteristic.eventOnlyCharacteristic = characteristic.eventOnlyCharacteristic;
      hapCharacteristic.value = characteristic.value;
      characteristics.push(hapCharacteristic);
    }

    hapService._sideloadCharacteristics(characteristics);

    servicesMap[service.UUID + (service.subtype || "")] = hapService;
    services.push(hapService);
  }

  if (data.linkedServices) {
    var linkedServices = data.linkedServices;
    for (var key in linkedServices) {
      var primaryService = servicesMap[key];
      if (primaryService) {