Exemplo n.º 1
0
    notify : function (message, controllers, source, fileName, payload) {
      var runCommand = require(__dirname + '/../lib/runCommand'),
          deviceId;

      for (deviceId in controllers) {
        if ((controllers[deviceId].config) && (deviceId !== source)) {
          switch (controllers[deviceId].config.typeClass) {
            case 'clientNotify' :
              runCommand.runCommand(deviceId, 'text-' + message, source, null, null, null, null, fileName);
            break;

            case 'clientSpeech' :
            case 'sms'          :
            case 'speech'       :
            case 'gerty'        :
              runCommand.runCommand(deviceId, 'text-' + message, source);
            break;

            case 'pushover'     :
              runCommand.runCommand(deviceId, 'text-' + message, source, null, null, null, null, payload);
            break;

            case 'clientVibrate' :
              runCommand.runCommand(deviceId, 'text-5', source);
            break;
          }
        }
      }
    }
Exemplo n.º 2
0
    init : function (controller) {
      var runCommand = require(__dirname + '/../../lib/runCommand');

      runCommand.runCommand(controller.config.deviceId, 'state', controller.config.deviceId);
      runCommand.runCommand(controller.config.deviceId, 'list', controller.config.deviceId);

      controller.markup = controller.markup.replace('{{FOSCAM_DYNAMIC}}', 'http://' + controller.config.deviceIp + '/videostream.cgi?user='******'&pwd=' + controller.config.password);

      return controller;
    },
Exemplo n.º 3
0
    fire : function(device, command, controllers) {
      var runCommand = require(__dirname + '/../lib/runCommand'),
          callback,
          deviceId;

      if((command === 'AlarmOn') || (command === 'AlarmOff')) {
        callback = function(deviceId, err, reply, params) {
          var deviceState = require('../lib/deviceState'),
              message     = 'err';

          params = params || {};

          if(reply) {
            message = 'ok';
          }

          params.state = message;

          deviceState.updateState(deviceId, controllers[deviceId].config.typeClass, params);
        };

        setTimeout(function() {
            console.log('\x1b[35mFoscam\x1b[0m: Fetching alarm state');

            controllers[device].controller.state(controllers[device], callback, controllers[device].config);
        }, 250);

        for(deviceId in controllers) {
          if((deviceId !== 'config') && (controllers[deviceId].config.typeClass === 'speech')) {
            runCommand.runCommand(deviceId, command === 'AlarmOn' ? 'text-Camera armed' : 'text-Camera disarmed', controllers, 'single', false);
          }
        }
      }
    }
Exemplo n.º 4
0
      smartThingsMood = function(command, controllers) {
        var mood = 'HAPPY',
            device,
            deviceId;

        for(device in controllers) {
          if(device !== 'config') {
            if(controllers[device].config.typeClass === 'jarvis') {
              deviceId = device;

              break;
            }
          }
        }

        switch(command) {
          case 'subdevice-mode-Away' :
            mood = 'INDIFFERENT';
          break;

          case 'subdevice-mode-Night' :
            mood = 'SLEEP';
          break;

          case 'subdevice-mode-Home' :
            mood = 'HAPPY';
          break;
        }

        if(deviceId) {
          runCommand.runCommand(deviceId, mood);
        }
      };
Exemplo n.º 5
0
        fs.readFile(__dirname + '/../../cache/nestAuth.json', 'utf-8', function (err, data) {
          var runCommand  = require(__dirname + '/../../lib/runCommand');

          // We need to retrieve the auth token.
          if (err) {
            that.getAuth({ device : { deviceId : controller.config.deviceId, username : controller.config.username, password : controller.config.password } }, controller);
          }

          // If we have a presumed good auth token, we can populate the device list.
          else if (data) {
            try {
              controller.config.auth = JSON.parse(data);
            }

            catch (catchErr) {
              console.log('\x1b[31m' + controller.config.title + '\x1b[0m: Auth cache could not be read');
            }

            if (controller.config.auth) {
              if ((controller.config.auth.expire) && (controller.config.auth.expire > now)) {
                expired = false;

                if (typeof controller.config.auth.url === 'string') {
                  runCommand.runCommand(controller.config.deviceId, 'list', controller.config.deviceId);
                }
              }

              else {
                that.getAuth({ device : { deviceId : controller.config.deviceId, username : controller.config.username, password : controller.config.password } }, controller);
              }
            }
          }
        });
Exemplo n.º 6
0
    poll : function(deviceId, controllers) {
      var runCommand = require(__dirname + '/../lib/runCommand');

      if(controllers[deviceId].controller.stocksOpen({ device : { deviceId : deviceId, title : controllers[deviceId].config.title } })) {
        runCommand.runCommand(deviceId, 'list');
      }
    }
Exemplo n.º 7
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);
Exemplo n.º 8
0
          callback = function(err, stocks) {
            var runCommand = require(__dirname + '/../lib/runCommand'),
                message    = '',
                i          = 0,
                stockName;

            if((controller.config.limits) && (stocks)) {
              for(stockName in controller.config.limits) {
                if((typeof controller.config.limits[stockName].sell !== 'undefined') && (stocks[stockName].price >= controller.config.limits[stockName].sell)) {
                  message = message + 'Your ' + stocks[stockName].name + ' stock is doing well at ' + stocks[stockName].ask + '.  Think about selling?  ';
                }

                else if((typeof controller.config.limits[stockName].buy !== 'undefined') && (stocks[stockName].price <= controller.config.limits[stockName].buy)) {
                  message = message + 'Your ' + stocks[stockName].name + ' stock is low at ' + stocks[stockName].ask + '.  Think about buying?  ';
                }

                else {
                  console.log('Schedule: ' + stocks[stockName].name + ' is at ' + stocks[stockName].price + ' - within range');
                }
              }
            }

            if(message) {
              for(i; i < controller.config.notify.length; i += 1) {
                if(typeof controllers[controller.config.notify[i]] !== 'undefined') {
                  runCommand.runCommand(controller.config.notify[i], 'text-' + message, controllers, 'single', false);
                }
              }
            }
          };
Exemplo n.º 9
0
    announceMoisture : function(device, command, controllers, values, config) {
      var runCommand = require(__dirname + '/../lib/runCommand'),
          translate  = require(__dirname + '/../lib/translate'),
          message    = '',
          value,
          deviceId;

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

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

        if(message) {
          for(deviceId in controllers) {
            if(deviceId !== 'config') {
              runCommand.runCommand(deviceId, 'text-' + message);
            }
          }
        }
      }
    }
Exemplo n.º 10
0
		function unpackSdk() {
			driverUtils.runCommand("tar -xvf *.zip", driverUtils.logStderr, function(error, stdout, stderr) {
				var configSetsPath;

				if (error !== null) {
					driverUtils.log("error <" + error + "> occurred when trying to unpack SDK");
					process.exit(1);
				}

				process.chdir(driverGlobal.driverDir);
				driverUtils.setCurrentTiSdk();

				/*
				Make sure we use the tests that are part of the downloaded SDK and not the local driver 
				instance itself.  If the SDK does not have anvil tests (older version of the SDK) then keep
				using the local tests
				*/
				configSetsPath = path.join(driverGlobal.config.currentTiSdkDir, "anvil", "configSet");
				if (path.existsSync(configSetsPath)) {
					driverGlobal.configSetDir = configSetsPath;
				}

				callback();
			});
		}
Exemplo n.º 11
0
		driverUtils.runCommand("adb shell am start -n com.appcelerator.harness/.HarnessActivity", driverUtils.logStdout, function(error, stdout, stderr) {

			if (stdout.indexOf("Error") != -1) {
				driverUtils.log("error encountered when running harness: " + stdout);

				driverUtils.log("Trying to run alternative harness name : " );

				driverUtils.runCommand("adb shell am start -n org.appcelerator.titanium.testharness/.Test_harnessActivity", driverUtils.logStdout, function(error,stdout, stderr) {
					if (stdout.indexOf("Error") != -1) {
						driverUtils.log("error encountered when running harness: " + stdout);
						if (errorCallback) {
							errorCallback();
						}
					} else {
						driverUtils.log("running harness");
						if (successCallback) {
							successCallback();
						}
					}
				});
			} else {
				driverUtils.log("running harness");
				if (successCallback) {
					successCallback();
				}
			}
		});
Exemplo n.º 12
0
	var uninstallHarness = function(successCallback, errorCallback) {
		driverUtils.runCommand("adb uninstall com.appcelerator.harness", driverUtils.logStdout, function(error, stdout, stderr) {
			if (stdout.indexOf("Failure") != -1) {
				driverUtils.log("error encountered when uninstalling harness: " + stdout);
				driverUtils.runCommand("adb uninstall org.appcelerator.titanium.testharness", driverUtils.logStdout, function(error, stdout, stderr) {
					if (stdout.indexOf("Failure") != -1) {
						driverUtils.log("error encountered when uninstalling harness: " + stdout);
							if (successCallback) {
								successCallback();
							}
					} else {
						driverUtils.log("harness uninstalled");
						if (successCallback) {
							successCallback();
						}
					}
				});
			} else {
				driverUtils.log("harness uninstalled");
				if (successCallback) {
					successCallback();
				}
			}
		});
	};
Exemplo n.º 13
0
	var closeSimulator = function(callback) {
		var closeIphoneCallback = function() {
			util.runCommand("/usr/bin/killall 'iPhone Simulator'", 2, function(error) {
				if (error != null) {
					util.log("error encountered when closing iPhone simulator: " + error);

				} else {
					util.log("iPhone simulator closed");
				}

				callback();
			});
		}

		util.runCommand("/usr/bin/killall 'ios-sim'", 2, function(error) {
			if (error != null) {
				util.log("error encountered when closing ios-sim: " + error);

			} else {
				util.log("ios-sim closed");
			}

			closeIphoneCallback();
		});
	};
Exemplo n.º 14
0
        callback = function(err, stocks) {
          var message = '',
              i       = 0,
              stockName;

          deviceState.updateState(deviceId, 'stocks', { state : 'ok', value : stocks });

          if((controller.config.limits) && (stocks)) {
            for(stockName in controller.config.limits) {
              if((typeof controller.config.limits[stockName].sell !== 'undefined') && (stocks[stockName]) && (stocks[stockName].price >= controller.config.limits[stockName].sell)) {
                message = message + 'Your ' + stocks[stockName].name + ' stock is doing well at ' + stocks[stockName].ask + '.  Think about selling?  ';
              }

              else if((typeof controller.config.limits[stockName].buy !== 'undefined') && (stocks[stockName]) && (stocks[stockName].price <= controller.config.limits[stockName].buy)) {
                message = message + 'Your ' + stocks[stockName].name + ' stock is low at ' + stocks[stockName].ask + '.  Think about buying?  ';
              }

              else if(stocks[stockName]){
                console.log('\x1b[35mSchedule\x1b[0m: ' + stocks[stockName].name + ' is at ' + stocks[stockName].price + ' - within range');
              }

              else {
                console.log('\x1b[31mSchedule\x1b[0m: Failed to fetch valid stock data');
              }
            }
          }

          if(message) {
            console.log('\x1b[35mSchedule\x1b[0m: ' + message);

            for(i; i < controller.config.notify.length; i += 1) {
              if(typeof controllers[controller.config.notify[i]] !== 'undefined') {
                if(controllers[controller.config.notify[i]].config.typeClass === 'mp3') {
                  runCommand.runCommand(controller.config.notify[i], 'text-cash', controllers, 'single', false);
                }

                else {
                  runCommand.runCommand(controller.config.notify[i], 'text-' + message, controllers, 'single', false);
                }
              }
            }
          }
        };
Exemplo n.º 15
0
	var runHarness = function(errorCallback) {
		util.runCommand("adb shell am start -a android.intent.action.VIEW -n com.android.browser/.BrowserActivity -d " + driverGlobal.httpHost + ":" + driverGlobal.httpPort + "/index.html", 2, function(error) {
			if (error != null) {
				util.log("error encountered when running harness: " + error);
				if (errorCallback) {
					errorCallback();
				}
			}
		});
	};
Exemplo n.º 16
0
	var runHarness = function(errorCallback) {
		driverUtils.runCommand("adb shell am start -a android.intent.action.VIEW -d " + driverGlobal.httpHost + ":" + driverGlobal.config.httpPort + "/index.html?" + Math.floor(Math.random() * 100000), driverUtils.logStdout, function(error) {
			if (error !== null) {
				driverUtils.log("error encountered when running harness: " + error);
				if (errorCallback) {
					errorCallback();
				}
			}
		});
	};
Exemplo n.º 17
0
    gerty : function (device, command, controllers, values, config, appParams) {
      var translate       = require(__dirname + '/../lib/translate'),
          runCommand      = require(__dirname + '/../lib/runCommand'),
          gertyRunCommand = require(__dirname + '/gerty/runCommand'),
          gertyMood       = require(__dirname + '/gerty/mood'),
          utterance       = translate.findSynonyms('gerty', controllers.config.language),
          deviceConfig    = ((controllers[device]) && (controllers[device].config)) || {},
          ignoreNegative  = deviceConfig.ignoreNegative,
          text            = '',
          tempDevice      = '',
          acted           = false;

      // If it's a command explicitly sent to Gerty to act on.
      if((deviceConfig.typeClass === 'gerty') && (command.indexOf('text-') === 0) &&
         ((appParams.source === 'gerty') || (appParams.source === 'single') || (appParams.source === 'macro'))) {
        // You can configure Gerty to only act on inputted text that mention the
        // name you configure.
        if((!deviceConfig.address) || ((deviceConfig.address) && (command.toUpperCase().indexOf(deviceConfig.title.toUpperCase()) !== -1))) {
          text = command.replace('text-', '').toUpperCase();

          gertyMood.setEmotion(text, device, controllers.config.language);

          acted = gertyRunCommand.setDevice(text, controllers, device, config.macros, controllers.config.language);

          if(acted === true) {
            utterance = utterance.AFFIRMATIVE[Math.floor(Math.random() * utterance.AFFIRMATIVE.length)];
          }

          else if((acted === false) && (!ignoreNegative)) {
            utterance = utterance.NEGATIVE[Math.floor(Math.random() * utterance.NEGATIVE.length)];
          }

          else {
            utterance = acted || '';
          }

          for(tempDevice in controllers) {
            if(tempDevice !== 'config') {
              if((controllers[tempDevice].config.typeClass === 'speech') || (controllers[tempDevice].config.typeClass === 'clientSpeech')) {
                runCommand.runCommand(tempDevice, 'text-' + utterance);
              }
            }
          }
        }
      }

      // Otherwise, see if it's a command that's sent to another controller
      // that Gerty is delegated on.
      else if(deviceConfig) {
        if(deviceConfig.typeClass !== 'gerty') {
          gertyRunCommand.setDeviceUpdate(device, deviceConfig.typeClass, command, values, controllers);
        }
      }
    }
Exemplo n.º 18
0
(function() {
    'use strict';

    var logger = require('jsdoc/util/logger');
    var path = require('jsdoc/path');
    var runtime = require('jsdoc/util/runtime');

    var cli = require( path.join(global.env.dirname, 'cli') );

    cli.setVersionInfo()
        .loadConfig();

    if (!global.env.opts.test) {
        cli.configureLogger();
    }

    cli.logStart();

    function cb(errorCode) {
        cli.logFinish();
        cli.exit(errorCode || 0);
    }

    // On Rhino, we use a try/catch block so we can log the Java exception (if available)
    if ( runtime.isRhino() ) {
        try {
            cli.runCommand(cb);
        }
        catch(e) {
            if (e.rhinoException) {
                logger.fatal( e.rhinoException.printStackTrace() );
            } else {
                console.trace(e);
                cli.exit(1);
            }
        }
    }
    else {
        cli.runCommand(cb);
    }
})();
Exemplo n.º 19
0
          gertyAnnounce    = function (controllers, utterance) {
            var runCommand = require(__dirname + '/../lib/runCommand'),
                tempDevice = '';

            for (tempDevice in controllers) {
              if (tempDevice !== 'config') {
                if ((controllers[tempDevice].config.typeClass === 'speech') || (controllers[tempDevice].config.typeClass === 'clientSpeech')) {
                  runCommand.runCommand(tempDevice, 'text-' + utterance);
                }
              }
            }
          };
Exemplo n.º 20
0
		var installCallback = function() {
			var apkname , apkpath, files;
			console.log("reached installharness");

			if(path.existsSync(path.resolve(driverGlobal.harnessDir, "android", "harness", "build", "android", "bin"))) {
				var files = fs.readdirSync(path.resolve(driverGlobal.harnessDir, "android", "harness", "build", "android", "bin"));
				if (files) {

					files.filter(function(file) {
									return file.substr(-4) == '.apk' ;
								}).forEach(function(file) {
												if(file != 'app-unsigned.apk') {
													apkname = file;
												}
											});

					if(typeof apkname === undefined) {
						driverUtils.log("harness is not built, building");
						buildHarness(installCallback, errorCallback);
					} else {
						apkpath = path.resolve(driverGlobal.harnessDir, "android", "harness", "build", "android", "bin", apkname);
						if (path.existsSync(apkpath)) {
							driverUtils.runCommand("adb install -r " + apkpath, driverUtils.logStdout, function(error, stdout, stderr) {

								if (stdout.indexOf("Failure [INSTALL_FAILED_ALREADY_EXISTS]") != -1) {
									uninstallHarness(installCallback, errorCallback);
								}
								else if (stdout.indexOf("Failure") != -1) {
									driverUtils.log("error encountered when installing harness: " + stdout);
									if (errorCallback) {
										errorCallback();
									}
								} else {
									driverUtils.log("harness installed" + stdout);
									if (successCallback) {
										setTimeout(successCallback, 5000);
									}
								}
							});
						} else {
							driverUtils.log("harness is not built, building");
							buildHarness(installCallback, errorCallback);
						}
					}
				} else {
					driverUtils.log("harness is not built, building");
					buildHarness(installCallback, errorCallback);
				}
			} else {
				driverUtils.log("harness is not built, building");
				buildHarness(installCallback, errorCallback);
			}
		};
Exemplo n.º 21
0
                  response.once('end', function() {
                    if(commandType) {
                      runCommand = require(__dirname + '/../lib/runCommand');

                      wemo.callback(null, wemoState);
                      runCommand.runCommand(config.device.deviceId, 'state', config.device.deviceId);
                    }

                    else {
                      wemo.callback(null, dataReply);
                    }
                  });
Exemplo n.º 22
0
		var closeIphoneCallback = function() {
			driverUtils.runCommand("/usr/bin/killall 'iPhone Simulator'", driverUtils.logStdout, function(error) {
				if (error !== null) {
					driverUtils.log("error encountered when closing iPhone simulator: " + error);

				} else {
					driverUtils.log("iPhone simulator closed");
				}

				callback();
			});
		};
Exemplo n.º 23
0
	var connectToHarness = function(errorCallback) {
		var retryCount = 0;

		var connectCallback = function() {
			connection = net.connect(driverGlobal.config.androidSocketPort);

			connection.on('data', function(data) {
				var responseData = common.processHarnessMessage(data);
				if (responseData) {
					connection.write(responseData);
				}
			});
			connection.on('close', function() {
				this.destroy();

				if (stoppingHarness === true) {
					stoppingHarness = false;
					return;
				}

				if (retryCount < driverGlobal.config.maxSocketConnectAttempts) {
					driverUtils.log("unable to connect, retry attempt " + (retryCount + 1) + "...");
					retryCount += 1;

					setTimeout(function() {
						connectCallback();
					}, 1000);

				} else {
					driverUtils.log("max number of retry attempts reached");
					errorCallback();
				}
			});
			connection.on('error', function() {
				this.destroy();
			});
			connection.on('timeout', function() {
				this.destroy();
			});
		};

		driverUtils.runCommand("adb forward tcp:" + driverGlobal.config.androidSocketPort + " tcp:" + driverGlobal.config.androidSocketPort, driverUtils.logStdout, function(error) {
			if (error !== null) {
				driverUtils.log("error encountered when setting up port forwarding for <" + driverGlobal.config.androidSocketPort + ">");
				errorCallback();

			} else {
				driverUtils.log("port forwarding activated for <" + driverGlobal.config.androidSocketPort + ">");
				connectCallback();
			}
		});
	};
Exemplo n.º 24
0
      notify = function(message) {
        var deviceId;

        for(deviceId in controllers) {
          if(controllers[deviceId].config) {
            switch(controllers[deviceId].config.typeClass) {
              case 'pushover' :
              case 'sms'      :
              case 'speech'   :
                runCommand.runCommand(deviceId, 'text-' + message);
              break;
            }
          }
        }
      };
Exemplo n.º 25
0
                fs.writeFile(localPath + fileName, rawImage, 'binary', function(err) {
                  var runCommand;

                  if (err) {
                    console.log('\x1b[31m' + title + '\x1b[0m: Unable to save ' + fileName);
                  }

                  else {
                    // Issue a full command to ensure we have the right
                    // callback.
                    runCommand = require(__dirname + '/../../lib/runCommand');
                    runCommand.runCommand(foscam.deviceId, 'list', foscam.deviceId);

                    console.log('\x1b[35m' + title + '\x1b[0m: Image saved as ' + fileName);
                  }
                });
Exemplo n.º 26
0
	var runHarness = function(successCallback, errorCallback) {
		driverUtils.runCommand("adb shell am start -n com.appcelerator.harness/.HarnessActivity", driverUtils.logStdout, function(error) {
			if (error !== null) {
				driverUtils.log("error encountered when running harness: " + error);
				if (errorCallback) {
					errorCallback();
				}

			} else {
				driverUtils.log("running harness");
				if (successCallback) {
					successCallback();
				}
			}
		});
	};
Exemplo n.º 27
0
	var uninstallHarness = function(successCallback, errorCallback) {
		driverUtils.runCommand("adb uninstall com.appcelerator.harness", driverUtils.logStdout, function(error) {
			if (error !== null) {
				driverUtils.log("error encountered when uninstalling harness: " + error);
				if (errorCallback) {
					errorCallback();
				}

			} else {
				driverUtils.log("harness uninstalled");
				if (successCallback) {
					successCallback();
				}
			}
		});
	};
Exemplo n.º 28
0
	this.deviceIsConnected = function(callback) {
		driverUtils.runCommand("adb devices", driverGlobal.logLevels.quiet, function(error, stdout, stderr) {
			var searchString = "List of devices attached";
			var deviceListString = "";

			var startPos = stdout.indexOf(searchString);
			if (startPos > -1) {
				var deviceListString = stdout.substring(startPos + searchString.length, stdout.length);
				deviceListString = deviceListString.replace(/\s/g,"");
			}

			if (deviceListString.length < 1) {
				callback(false);

			} else {
				callback(true);
			}
		});
	};
Exemplo n.º 29
0
        fs.readFile(__dirname + '/../../cache/smartthingsAuth.json', function (err, data) {
          var runCommand = require(__dirname + '/../../lib/runCommand');

          // We need to prompt the user to retrieve the auth token.
          if(err) {
            console.log('\x1b[31m=====================================================================\x1b[0m');
            console.log('\x1b[31mWARNING\x1b[0m: ' + controller.config.title + ': Attempting to load controller that requires');
            console.log('\x1b[31mWARNING\x1b[0m: additional OAuth configuration!');
            console.log('\x1b[31mWARNING\x1b[0m: Visit this URL to authenticate:');
            console.log('https://graph.api.smartthings.com/oauth/authorize?response_type=code&client_id=' + controller.config.clientId + '&redirect_uri=' + ssl + '://' + config.serverIp + ':' + config.serverPort + '/oauth/' + controller.config.deviceId + '&scope=app');
            console.log('\x1b[31m=====================================================================\x1b[0m');
          }

          else if(data) {
            if(data.toString()) {
              try {
                controller.config.auth = JSON.parse(data.toString());
              }

              catch(catchErr) {
                console.log('\x1b[31m' + controller.config.title + '\x1b[0m: Failed to parse auth file');
              }

              if(controller.config.auth) {
                if(typeof controller.config.auth.url === 'string') {
                  runCommand.runCommand(controller.config.deviceId, 'list', controller.config.deviceId);
                }

                else {
                  controller.controller.oauthUrl(auth, controller);
                }
              }

              else {
                console.log('\x1b[31m' + controller.config.title + '\x1b[0m: Auth cache is invalid');
              }
            }

            else {
              console.log('\x1b[31m' + controller.config.title + '\x1b[0m: Auth cache is empty');
            }
          }
        });
Exemplo n.º 30
0
            fs.readFile(__dirname + '/../cache/smartthingsAuth.json', function(err, auth) {
              var runCommand  = require(__dirname + '/../lib/runCommand');

              if(auth.toString()) {
                controller.config.auth = JSON.parse(auth.toString());

                if(typeof controller.config.auth.url === 'string') {
                  runCommand.runCommand(controller.config.deviceId, 'list', controller.config.deviceId);
                }

                else {
                  controller.controller.oauthUrl(auth, controller);
                }
              }

              else {
                console.log('\x1b[31m' + controller.config.title + '\x1b[0m: Auth cache is empty');
              }
            });