announcePresence : function (device, command, controllers, values, config) {
      var runCommand = require(__dirname + '/../lib/runCommand'),
          translate  = require(__dirname + '/../lib/translate'),
          notify     = require(__dirname + '/../lib/notify'),
          message    = '',
          presence   = config.presence || [],
          value,
          deviceId;

      if(command.indexOf('subdevice-state-presence-') === 0) {
        command = command.split('subdevice-state-presence-').join('');
        value   = command.split('-');
        command = value[0];
        value   = value[1];

        if(presence.indexOf(command) !== -1) {
          if(value === 'on') {
            message = translate.translate('{{i18n_ARRIVED}}', 'smartthings', controllers.config.language).replace('{{LABEL}}', command);
          }

          else if(value === 'off') {
            message = translate.translate('{{i18n_LEFT}}', 'smartthings', controllers.config.language).replace('{{LABEL}}', command);
          }

          if(message) {
            notify.notify(message, controllers, device);
          }
        }
      }
    }
Exemple #2
0
        GLOBAL.bot.Dispatcher.on(Discordie.Events.MESSAGE_CREATE, (res) => {
            logger.notify('info', 'New message:\n  From: ' + res.message.author.username + '\n  Content: ' + res.message.content + '\n  Timestamp: ' + res.message.timestamp );

            let command_string = res.message.content;

            // Make sure we're talking to K9!
            if(! string(command_string.toLowerCase()).startsWith(trigger.toLowerCase()) && ! utils.isBotMessage(res.message.channel_id)) {
                return;
            }

            // Parse out any arguements
            command_string = command_string.split(' ');
            let command    = command_string.reverse().pop();
            let arguement  = command_string.reverse().join(' ');


            // Strip trigger
            command = string(command.toLowerCase()).chompLeft(trigger.toLowerCase()).s;

            // Find containing module
            let module = modules.search(command);

            // Prefix command
            command = '_' + command;

            // Run the command!
            if(module) {
                GLOBAL.k9modules[module][command](res, arguement);
            }
        });
Exemple #3
0
        setTimeout(function () {
          var status = checkState(),
              currDevice,
              i      = 0;

          if (status.thermostat.length && status.contact.length) {
            for (currDevice in controllers) {
              if (controllers[currDevice].config) {
                if (controllers[currDevice].config.typeClass === 'nest') {
                  for (i; i < status.thermostat.length; i += 1) {
                    runCommand.runCommand(currDevice, 'subdevice-' + status.thermostat[i].label + '-off');
                  }

                  message = that.formatMessage('off', status.contact, status.thermostat[0].state, controllers.config.language);
                  notify.notify(message, controllers, deviceId);
                }
              }
            }
          }

          // Don't hammer us if we're messing with the thermostat.
          setTimeout(function () {
            that.governor = false;
          }, 60000);
        }, delay * 1000);
    announceFoscam : function (device, command, controllers, values, config) {
      var runCommand   = require(__dirname + '/../lib/runCommand'),
          translate    = require(__dirname + '/../lib/translate'),
          deviceState  = require(__dirname + '/../lib/deviceState'),
          notify       = require(__dirname + '/../lib/notify'),
          currentState = deviceState.getDeviceState(device),
          message      = '',
          deviceId;

      if((currentState) && (currentState.value)) {
        if((command === 'ALARM_ON') || (command === 'ALARM_OFF')) {
          if((command === 'ALARM_ON') && (currentState.value === 'off')) {
            message = translate.translate('{{i18n_CAMERA_ARMED}}', 'foscam', controllers.config.language);
          }

          else if((command === 'ALARM_OFF') && (currentState.value === 'on')) {
            message = translate.translate('{{i18n_CAMERA_DISARMED}}', 'foscam', controllers.config.language);
          }

          if(message) {
            notify.notify(message, controllers, device);
          }
        }
      }
    }
 it('should not return an error on valid request', function(done){
     hipchatter.notify(settings.test_room, 
         {
             message: "Test Message from Mocha", 
             token: settings.room_token
         }, function(err, response){
             expect(err).to.be.null;
             done();
         }
     );
 });
Exemple #6
0
var server = app.listen(webPort, function () {
    var message = 'App listening at http://0.0.0.0:' + webPort;
    helper.notify('Spelling Corrector Server', message);
    console.log(message + '\n');

    indexer = new Indexer({ distLimit: distanceLimit, distMode: distanceMode });

    if (shouldLoadInformation) {
        runner.initAndStart(indexer);
    } else {
        runner.start(indexer);
    }
});
Exemple #7
0
 /**
  * Saves a config file to disk
  *
  * @since       0.0.1
  * @access      public
  * @param       string handle The handle of a specific config file to save
  * @return      {void}
  */
 save(handle) {
     if(handle) {
         if(configs.hasOwnProperty(handle)) {
             GLOBAL.k9configs[handle].save();
             logger.notify('info', 'Configuration saved successfully.');
         } else {
             logger.log('error', 'Config file ' + configs[handle] + ' not found!');
             return;
         }
     } else {
         logger.log('silly', 'No config file specified!');
         return;
     }
 }
    announceNest : function (device, command, controllers, values, config) {
      var runCommand  = require(__dirname + '/../lib/runCommand'),
          translate   = require(__dirname + '/../lib/translate'),
          notify      = require(__dirname + '/../lib/notify'),
          message     = '',
          tempMessage = '',
          i           = 0,
          subDevice,
          deviceId,
          rawMacro,
          macro;

      if(values.protect) {
        for(subDevice in values.protect) {
          if(values.protect[subDevice].smoke !== 'ok') {
            tempMessage = translate.translate('{{i18n_SMOKE_DETECTED}}', 'nest', controllers.config.language).replace('{{LABEL}}', values.protect[subDevice].label);

            if(message) {
              message = message + ' ';
            }

            message = message + tempMessage;
          }

          if(values.protect[subDevice].co !== 'ok') {
            tempMessage = translate.translate('{{i18n_CO_DETECTED}}', 'nest', controllers.config.language).replace('{{LABEL}}', values.protect[subDevice].label);

            if(message) {
              message = message + ' ';
            }

            message = message + tempMessage;
          }
        }

        if(message) {
          notify.notify(message, controllers, device);

          // If you have a macro assigned to this specific Mode, we'll act upon
          // it.
          if(config.macro) {
            rawMacro = config.macro.split(';');

            for(macro in rawMacro) {
              runCommand.macroCommands(rawMacro[macro]);
            }
          }
        }
      }
    }
Exemple #9
0
        setTimeout(function () {
          var notify     = require(__dirname + '/../lib/notify'),
              translate  = require(__dirname + '/../lib/translate'),
              runCommand = require(__dirname + '/../lib/runCommand'),
              message    = '',
              currDevice;

          if ((that.lastEvents.open <= that.lastEvents.close) &&
              (Math.abs(that.lastEvents.knock - that.lastEvents.open)  > delay) &&
              (Math.abs(that.lastEvents.knock - that.lastEvents.close) > delay)) {
            message = translate.translate('{{i18n_DOOR_KNOCK}}', 'smartthings', controllers.config.language).split('{{LABEL}}').join(config.contact);

            notify.notify(message, controllers, deviceId);

            for (currDevice in controllers) {
              if ((controllers[currDevice].config) && ((controllers[currDevice].config.typeClass === 'mp3') || (controllers[currDevice].config.typeClass === 'clientMp3'))) {
                runCommand.runCommand(currDevice, 'text-doorbell');
              }
            }
          }
        }, delay);
    announceDLinkCamera : function (deviceId, command, controllers) {
      var translate    = require(__dirname + '/../lib/translate'),
          deviceState  = require(__dirname + '/../lib/deviceState'),
          notify       = require(__dirname + '/../lib/notify'),
          currentState = deviceState.getDeviceState(deviceId),
          message      = '';

      if ((currentState) && (currentState.value)) {
        if ((command === 'ALARM_ON') || (command === 'ALARM_OFF')) {
          if ((command === 'ALARM_ON') && (currentState.value.alarm === 'off')) {
            message = translate.translate('{{i18n_CAMERA_ARMED}}', 'dLinkCamera', controllers.config.language);
          }

          else if ((command === 'ALARM_OFF') && (currentState.value.alarm === 'on')) {
            message = translate.translate('{{i18n_CAMERA_DISARMED}}', 'dLinkCamera', controllers.config.language);
          }

          if (message) {
            notify.notify(message.split('{{CAMERA}}').join(controllers[deviceId].config.title), controllers, deviceId);
          }
        }
      }
    }
Exemple #11
0
    windowOpen : function (deviceId, command, controllers, values, config) {
      var notify      = require(__dirname + '/../lib/notify'),
          deviceState = require(__dirname + '/../lib/deviceState'),
          runCommand  = require(__dirname + '/../lib/runCommand'),
          that        = this,
          delay       = config.delay || 60,
          checkState,
          message     = '',
          status;

      checkState = function () {
        var currDevice,
            currentDevice = {},
            status        = { thermostat : [], contact : [] },
            subdeviceId,
            subdevice;

        for (currDevice in controllers) {
          if ((controllers[currDevice].config) && (controllers[currDevice].config.typeClass === 'nest')) {
            currentDevice = deviceState.getDeviceState(currDevice);

            if (currentDevice.value) {
              for (subdeviceId in currentDevice.value.devices) {
                if (currentDevice.value.devices.hasOwnProperty(subdeviceId)) {
                  subdevice = currentDevice.value.devices[subdeviceId];

                  if ((config.thermostat.indexOf(subdevice.label) !== -1) && (subdevice.type === 'thermostat') && (subdevice.state !== 'off') && (currentDevice.state !== 'err')) {
                    status.thermostat.push({ label : subdevice.label, state : subdevice.state });
                  }
                }
              }
            }
          }

          else if ((controllers[currDevice].config) && (controllers[currDevice].config.typeClass === 'smartthings')) {
            currentDevice = deviceState.getDeviceState(currDevice);

            if (currentDevice.value) {
              for (subdeviceId in currentDevice.value.devices) {
                if (currentDevice.value.devices.hasOwnProperty(subdeviceId)) {
                  subdevice = currentDevice.value.devices[subdeviceId];

                  if ((config.contact.indexOf(subdevice.label) !== -1) && (subdevice.type === 'contact') && (subdevice.state === 'on')) {
                    status.contact.push(subdevice.label);
                  }
                }
              }
            }
          }
        }

        return status;
      };

      status = checkState();

      // If something is on while a contact sensor is open, we'll first notify,
      // then wait a minute before we shut things down.
      if ((this.governor === false) && (status.thermostat.length) && (status.contact.length)) {
        this.governor = true;

        message = that.formatMessage('warn', status.contact, status.thermostat[0].state, controllers.config.language);
        notify.notify(message, controllers, deviceId);

        setTimeout(function () {
          var status = checkState(),
              currDevice,
              i      = 0;

          if (status.thermostat.length && status.contact.length) {
            for (currDevice in controllers) {
              if (controllers[currDevice].config) {
                if (controllers[currDevice].config.typeClass === 'nest') {
                  for (i; i < status.thermostat.length; i += 1) {
                    runCommand.runCommand(currDevice, 'subdevice-' + status.thermostat[i].label + '-off');
                  }

                  message = that.formatMessage('off', status.contact, status.thermostat[0].state, controllers.config.language);
                  notify.notify(message, controllers, deviceId);
                }
              }
            }
          }

          // Don't hammer us if we're messing with the thermostat.
          setTimeout(function () {
            that.governor = false;
          }, 60000);
        }, delay * 1000);
      }
    }
 it('should still support the convenience syntax', function(done){
     hipchatter.notify(settings.test_room, "Test Message from Mocha", settings.room_token, function(err, response){
         expect(err).to.be.null;
         done();
     });
 });
 it('should throw an error if no object is passed', function(done){
     hipchatter.notify(settings.test_room, function(err, response, body){
         expect(err.message).to.contain('options object to the notify function');
         done();
     });
 });