How to use the hap-nodejs.Characteristic.On 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 / accessories / Http.js View on Github external
getServices: function() {

    // you can OPTIONALLY create an information service if you wish to override
    // the default values for things like serial number, model, etc.
    var informationService = new Service.AccessoryInformation();
    
    informationService
      .setCharacteristic(Characteristic.Manufacturer, "HTTP Manufacturer")
      .setCharacteristic(Characteristic.Model, "HTTP Model")
      .setCharacteristic(Characteristic.SerialNumber, "HTTP Serial Number");
    
    var lightbulbService = new Service.Lightbulb();
    
    lightbulbService
      .getCharacteristic(Characteristic.On)
      .on('set', this.setPowerState.bind(this));
    
    lightbulbService
      .addCharacteristic(new Characteristic.Brightness())
      .on('set', this.setBrightness.bind(this));
    
    return [informationService, lightbulbService];
  }
};
github htreu / OpenHAB-HomeKit-Bridge / lib / Colorpicker.js View on Github external
if (finished === 4) {
          this.updatingFromOpenHAB = false;
        }
      }.bind(this)
    );
    // set saturation
    this.getCharacteristic(Characteristic.Saturation).setValue(saturation,
      function() { // callback to signal us iOS did process the update
        finished++;
        if (finished === 4) {
          this.updatingFromOpenHAB = false;
        }
      }.bind(this)
    );
    // update ON/OFF state
    this.getCharacteristic(Characteristic.On).setValue(power,
      function() { // callback to signal us iOS did process the update
        finished++;
        if (finished === 4) {
          this.updatingFromOpenHAB = false;
        }
      }.bind(this)
    );
	};
github Capevace / halbert / system / modules / switch / accessories.js View on Github external
const outlet = new Accessory(switchConfig.name, outletUUID);

  outlet
    .getService(Service.AccessoryInformation)
    .setCharacteristic(Characteristic.Manufacturer, 'HALBERT')
    .setCharacteristic(Characteristic.Model, `${switchConfig.type}-${switchConfig.protocol}-switch`)
    .setCharacteristic(Characteristic.SerialNumber, switchConfig.id);

  outlet.on('identify', (paired, callback) => {
    console.logger.info(`${switchConfig.name} was identified. Paired: ${paired}.`);
    callback();
  });

  outlet
    .addService(Service.Outlet, switchConfig.name)
    .getCharacteristic(Characteristic.On)
    .on('set', (value, callback) => {
      const action = value
        ? 'switch.on'
        : 'switch.off';

      runAction(action, {
        switchId: switchConfig.id
      });

      callback();
    });

  outlet
    .getService(Service.Outlet)
    .getCharacteristic(Characteristic.On)
    .on('get', (callback) => {
github nfarina / homebridge / accessories / mpdclient.js View on Github external
getServices: function() {

    var informationService = new Service.AccessoryInformation();
    
    informationService
      .setCharacteristic(Characteristic.Manufacturer, "MPD")
      .setCharacteristic(Characteristic.Model, "MPD Client")
      .setCharacteristic(Characteristic.SerialNumber, "81536334");
    
    var switchService = new Service.Switch();
    
    switchService.getCharacteristic(Characteristic.On)
      .on('get', this.getPowerState.bind(this))
      .on('set', this.setPowerState.bind(this));
    
    return [informationService, switchService];
  }
};
github nfarina / homebridge / accessories / WeMo.js View on Github external
WeMoAccessory.prototype.getServices = function() {
  
  if (this.service == "Switch") {
    var switchService = new Service.Switch(this.name);
    
    switchService
      .getCharacteristic(Characteristic.On)
      .on('get', this.getPowerOn.bind(this))
      .on('set', this.setPowerOn.bind(this));
    
    return [switchService];
  }
  else if (this.service == "GarageDoor") {
    var garageDoorService = new Service.GarageDoorOpener("Garage Door Opener");
    
    garageDoorService
      .getCharacteristic(Characteristic.TargetDoorState)
      .on('set', this.setTargetDoorState.bind(this));
    
    return [garageDoorService];
  }
  else if (this.service == "Light") {
    var lightbulbService = new Service.Lightbulb(this.name);
github nfarina / homebridge / accessories / GenericRS232Device.js View on Github external
getServices: function() {
    var switchService = new Service.Switch(this.name);
    var informationService = new Service.AccessoryInformation();

    informationService
      .setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
      .setCharacteristic(Characteristic.Model, this.model_name)
      .setCharacteristic(Characteristic.SerialNumber, this.id);

    switchService
      .getCharacteristic(Characteristic.On)
      .on('set', this.setPowerState.bind(this));

    return [informationService, switchService];
  }
}
github htreu / OpenHAB-HomeKit-Bridge / lib / subtypes / LightbulbItem.js View on Github external
buildAccessory(state) {
    let accessory = new Accessory(this.name,
      uuid.generate(this.constructor.name + this.name));

    let charactersiticOnOff = accessory
      .addService(Service.Lightbulb, this.name)
      .getCharacteristic(Characteristic.On);

    charactersiticOnOff.setValue(state === 'ON');

    charactersiticOnOff.on('set', this.updateOpenHabItem.bind(this));
    charactersiticOnOff.on('get', this.readOpenHabPowerState.bind(this));

    return accessory;
  };
github nfarina / homebridge / platforms / MiLight.js View on Github external
getServices: function() {
    var informationService = new Service.AccessoryInformation();

    informationService
      .setCharacteristic(Characteristic.Manufacturer, "MiLight")
      .setCharacteristic(Characteristic.Model, this.type)
      .setCharacteristic(Characteristic.SerialNumber, "MILIGHT12345");

    var lightbulbService = new Service.Lightbulb();

    lightbulbService
      .getCharacteristic(Characteristic.On)
      .on('set', this.setPowerState.bind(this));

    lightbulbService
      .addCharacteristic(new Characteristic.Brightness())
      .on('set', this.setBrightness.bind(this));

    lightbulbService
      .addCharacteristic(new Characteristic.Hue())
      .on('set', this.setHue.bind(this));

    return [informationService, lightbulbService];
  }
};
github SphtKr / homebridge-zway / isy-js.js View on Github external
ISYOutletAccessory.prototype.getServices = function() {
	var informationService = new Service.AccessoryInformation();
	
	informationService
      .setCharacteristic(Characteristic.Manufacturer, "SmartHome")
      .setCharacteristic(Characteristic.Model, this.device.deviceFriendlyName)
      .setCharacteristic(Characteristic.SerialNumber, this.device.address);	
	  
	var outletService = new Service.Outlet();
	
	this.outletService = outletService;
	this.informationService = informationService;	
    
    outletService
      .getCharacteristic(Characteristic.On)
      .on('set', this.setOutletState.bind(this));
	  
	outletService
	  .getCharacteristic(Characteristic.On)
	  .on('get', this.getOutletState.bind(this));
	  
	outletService
	  .getCharacteristic(Characteristic.OutletInUse)
	  .on('get', this.getOutletInUseState.bind(this));
    
    return [informationService, outletService];	
}
github Capevace / halbert / system / moduleRegistry / built-in / switch / accessories.js View on Github external
outlet
      .addService(Service.Outlet, switchConfig.name)
      .getCharacteristic(Characteristic.On)
      .on('set', (value, callback) => {
        const action = value ? 'switch.on' : 'switch.off';

        runAction(action, {
          switchId: switchConfig.id
        });

        callback();
      });

    outlet
      .getService(Service.Outlet)
      .getCharacteristic(Characteristic.On)
      .on('get', callback => {
        callback(null, getState(`switch_${switchConfig.id}`).state);
      });

    return outlet;
  }
};