How to use the hap-nodejs.init 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 Capevace / halbert / system / home-kit.js View on Github external
function homeKitSetup(moduleRegistry) {
  init();

  const bridge = new Bridge('H.A.L.B.E.R.T.', config.device.uuid);

  // Identification Event
  bridge.on('identify', (paired, callback) => {
    console.logger.info('HomeKit paired:', paired);
    callback();
  });

  const modules = moduleRegistry.getRegisteredModules();
  Object.keys(modules).forEach(moduleKey => {
    if (!modules[moduleKey].accessories) return;

    modules[
      moduleKey
    ].accessories.forEach(accessory => bridge.addBridgedAccessory(accessory));
github nfarina / homebridge / lib / cli.js View on Github external
var shuttingDown = false;

  program
    .version(version)
    .option('-C, --color', 'force color in logging', function() { require('./logger').forceColor(); })
    .option('-D, --debug', 'turn on debug level logging', function() { require('./logger').setDebugEnabled(true); })
    .option('-I, --insecure', 'allow unauthenticated requests (for easier hacking)', function() { insecureAccess = true; })
    .option('-P, --plugin-path [path]', 'look for plugins installed at [path] as well as the default locations ([path] can also point to a single plugin)', function(p) { Plugin.addPluginPath(p); })
    .option('-Q, --no-qrcode', 'do not issue QRcode in logging', function() { hideQRCode = true; })
    .option('-R, --remove-orphans', 'remove cached accessories for which plugin is not loaded', function() { cleanCachedAccessories = true; })
    .option('-T, --no-timestamp', 'do not issue timestamps in logging', function() { require('./logger').setTimestampEnabled(false); })
    .option('-U, --user-storage-path [path]', 'look for homebridge user files at [path] instead of the default location (~/.homebridge)', function(p) { User.setStoragePath(p); })
    .parse(process.argv);

  // Initialize HAP-NodeJS with a custom persist directory
  hap.init(User.persistPath());

  var server = new Server({cleanCachedAccessories:cleanCachedAccessories, insecureAccess:insecureAccess, hideQRCode:hideQRCode});

  var signals = { 'SIGINT': 2, 'SIGTERM': 15 };
  Object.keys(signals).forEach(function (signal) {
    process.on(signal, function () {
      if (shuttingDown) {
        return
      }
      shuttingDown = true;

      log.info("Got %s, shutting down Homebridge...", signal);

      server._teardown();
      setTimeout(function (){
        process.exit(128 + signals[signal]);
github agrippa1994 / FS20 / main.js View on Github external
if (error) {
      logger.error("Failed to connect to the serial interface, " + error);
      process.exit(0);
    }

    logger.info("Connection to the serial interface has been established");
  },
  function (error) {
    logger.error("Serial connection disconnected");
    process.exit(0);
  }
);

//--------------------------------------------------------------------------------------
// Initialize HAP
hap.init(path.join(__dirname, "hap-db"));

// Read all devices
var devices = hap.AccessoryLoader.loadDirectory(path.join(__dirname, "devices"));
var targetPort = 51826;

// Iterate through all devices
devices.forEach(device => {
  device.stateChange = (value, callback) => {
    logger.info(`Changing state of device ${device.username} to ${value} ...`);
    fs20.setDeviceState(device.code, value, (error, received) => {
      if (error)
        logger.error(`Can't change state of device ${device.username} to ${value}, ${error}`);
      else
        logger.info(`Changed state of device ${device.username} to ${value}, code: ${received.code}, text: ${received.text}`);

      if (error)
github mrsharpoblunto / it-gets-the-hose-again / web / lib / app.js View on Github external
function startHomekitServer(app) {
    hap.init();
    const accessory = require('./valve-accessory')(app.valveController);
    accessory.publish({
        port: config.HOMEKIT_PORT,
        username: config.HOMEKIT_USERNAME,
        pincode: clientConfig.HOMEKIT_PINCODE
    });
    app.logger.info('Published HomeKit Accessory Info');
}
github rdmtc / RedMatic-HomeKit / nodes / redmatic-homekit-tv.js View on Github external
module.exports = function (RED) {
    hap.init(path.join(RED.settings.userDir, 'homekit'));

    RED.httpAdmin.get('/redmatic-homekit-tv', (req, res) => {
        if (req.query.config) {
            const acc = accessories[req.query.config];
            if (acc) {
                res.status(200).send(JSON.stringify({setupURI: acc.setupURI()}));
            } else {
                res.status(500).send(JSON.stringify({}));
            }
        } else {
            res.status(404).send(JSON.stringify({}));
        }
    });

    class RedMaticHomeKitTv {
        constructor(config) {
github rdmtc / RedMatic-HomeKit / nodes / redmatic-homekit-bridge.js View on Github external
module.exports = function (RED) {
    hap.init(path.join(RED.settings.userDir, 'homekit'));

    RED.httpAdmin.get('/redmatic-homekit', (req, res) => {
        if (req.query.config && req.query.config !== '_ADD_') {
            const config = RED.nodes.getNode(req.query.config);
            if (!config || !config.bridge.isPublished) {
                res.status(500).send(JSON.stringify({}));
            } else {
                res.status(200).send(JSON.stringify({setupURI: config.bridge.setupURI()}));
            }
        } else {
            res.status(404).send(JSON.stringify({}));
        }
    });

    class RedMaticHomeKitBridge {
        constructor(config) {
github jensweigele / ioBroker.yahka / yahka.homekit-bridge.js View on Github external
function initHAP(storagePath, HAPdebugLogMethod) {
    if (hapInited) {
        return;
    }
    HAP.init(storagePath);
    debug.log = function () {
        HAPdebugLogMethod(util.format.apply(this, arguments));
    };
}
exports.initHAP = initHAP;
github rdmtc / RedMatic-HomeKit / nodes / redmatic-homekit-camera.js View on Github external
module.exports = function (RED) {
    hap.init(path.join(RED.settings.userDir, 'homekit'));

    RED.httpAdmin.get('/redmatic-homekit-camera', (req, res) => {
        if (req.query.config) {
            const acc = accessories[req.query.config];
            if (acc) {
                res.status(200).send(JSON.stringify({setupURI: acc.setupURI()}));
            } else {
                res.status(500).send(JSON.stringify({}));
            }
        } else {
            res.status(404).send(JSON.stringify({}));
        }
    });

    class RedMaticHomeKitCamera {
        constructor(config) {