<commit_before>var TelldusAPI = require('./telldus-live');

var publicKey   = '...'
  , privateKey  = '...'
  , token       = '...'
  , tokenSecret = '...'
  , cloud
  ;

cloud = new TelldusAPI.TelldusAPI({ publicKey  : publicKey
                                  , privateKey : privateKey }).login(token, tokenSecret, function(err, user) {
  if (!!err) return console.log('login error: ' + err.message);

  console.log('user: '); console.log(user); console.log(''); console.log('');

  cloud.getSensors(function(err, sensors) {
    var f, i;

    if (!!err) return console.log('getSensors: ' + err.message);

    f = function(offset, p, s) {
      return function(err, sensor) {
        var d, prop, type;

        if (!!err) return console.log(s + ' id=' + p.id + ': ' + err.message);

        console.log('sensor #' + offset + ' ' + s + ': '); console.log(sensor);
        type = null;
        for (d in sensor.data) if (sensor.data.hasOwnProperty(d)) {
          if ((d.name === 'temp') || (d.name === 'humidity')) type = 'meteo';
        }
        console.log('/device/climate' + (sensor.protocol || 'telldus') + '/' + (type || 'generic'));
        console.log('    uuid=teldus:' + sensor.id);
        console.log('    name: ' + sensor.name);
        console.log('    status: ' + (p.online === '1' ? 'present' : 'absent'));
        console.log('    lastSample: ' + sensor.lastUpdated * 1000);
        console.log('    info:');
        for (d in sensor.data) if (sensor.data.hasOwnProperty(d)) {
          prop = { temp : 'temperature' }[d.name] || d.name;
          console.log('      ' + prop + ': ' + d.value);
        }
        console.log('');
      };
    };

    console.log('sensors: '); console.log(sensors); console.log(''); console.log('');
    for (i = 0; i < sensors.length; i++) cloud.getSensorInfo(sensors[i], f(i, sensors[i], 'getSensorInfo'));
  }).getDevices(function(err, devices) {
    var f, i;

    if (!!err) return console.log('getDevices: ' + err.message);

    f = function(offset, p, s) {
      return function(err, device) {
        var d, type;

        if (!!err) return console.log(s + ' id=' + p.id + ': ' + err.message);

        console.log('device #' + offset + ' ' + s + ': '); console.log(device);
        type = null;
        d = device.protocol.split(':');
        type = { 'selflearning-switch' : 'dimmer'
               , codeswitch            : 'onoff' }[d[0]];
        if (!type) return;
        console.log('/device/climate' + (d[d.length - 1] || 'telldus') + '/' + (type || 'generic'));
        console.log('    uuid=teldus:' + device.id);
        console.log('    perform: off, on');
        console.log('    name: ' + device.name);
        console.log('    status: ' + (device.online === '1' ? 'present' : 'absent'));
        console.log('    info:');
        if (type === 'dimmer') console.log('      dimmer: percentage');
        console.log('');
      };
    };

    console.log('devices: '); console.log(devices); console.log(''); console.log('');
    for (i = 0; i < devices.length; i++) {
      if (devices[i].type === 'device') cloud.getDeviceInfo(devices[i], f(i, devices[i], 'getDeviceInfo'));
    }
  });
}).on('error', function(err) {
  console.log('background error: ' + err.message);
});
<commit_msg>* Split out the keys and tokens so that they don't   get committed by mistake. * check model instead of protocol to see if it is   a dimmer of on/off switch. * If it is a dimmer print the dim-level.<commit_after>var TelldusAPI = require('./telldus-live');
var secrets  = require('./secrets').MySecrets;

var publicKey   = secrets.publicKey?secrets.publicKey:'...'
  , privateKey  = secrets.privateKey?secrets.privateKey:'...'
  , token       = secrets.token?secrets.token:'...'
  , tokenSecret = secrets.tokenSecret?secrets.tokenSecret:'...'
  , cloud
  ;

cloud = new TelldusAPI.TelldusAPI({ publicKey  : publicKey
                                  , privateKey : privateKey }).login(token, tokenSecret, function(err, user) {
  if (!!err) return console.log('login error: ' + err.message);

  console.log('user: '); console.log(user); console.log(''); console.log('');

  cloud.getSensors(function(err, sensors) {
    var f, i;

    if (!!err) return console.log('getSensors: ' + err.message);

    f = function(offset, p, s) {
      return function(err, sensor) {
        var d, prop, type;

        if (!!err) return console.log(s + ' id=' + p.id + ': ' + err.message);

        console.log('sensor #' + offset + ' ' + s + ': '); console.log(sensor);
        type = null;
        for (d in sensor.data) if (sensor.data.hasOwnProperty(d)) {
          if ((d.name === 'temp') || (d.name === 'humidity')) type = 'meteo';
        }
        console.log('/device/climate' + (sensor.protocol || 'telldus') + '/' + (type || 'generic'));
        console.log('    uuid=teldus:' + sensor.id);
        console.log('    name: ' + sensor.name);
        console.log('    status: ' + (p.online === '1' ? 'present' : 'absent'));
        console.log('    lastSample: ' + sensor.lastUpdated * 1000);
        console.log('    info:');
        for (d in sensor.data) if (sensor.data.hasOwnProperty(d)) {
          prop = { temp : 'temperature' }[d.name] || d.name;
          console.log('      ' + prop + ': ' + d.value);
        }
        console.log('');
      };
    };

    console.log('sensors: '); console.log(sensors); console.log(''); console.log('');
    for (i = 0; i < sensors.length; i++) cloud.getSensorInfo(sensors[i], f(i, sensors[i], 'getSensorInfo'));
  }).getDevices(function(err, devices) {
    var f, i;

    if (!!err) return console.log('getDevices: ' + err.message);

    f = function(offset, p, s) {
      return function(err, device) {
        var d, type;

        if (!!err) return console.log(s + ' id=' + p.id + ': ' + err.message);

        console.log('device #' + offset + ' ' + s + ': '); console.log(device);
        type = null;
        d = device.model.split(':');
        type = { 'selflearning-switch' : 'onoff'
               , 'selflearning-dimmer' : 'dimmer'
               , 'codeswitch'          : 'onoff' }[d[0]];
        if (!type) return;
        console.log('/device/climate' + '/' + (d[d.length - 1] || 'telldus') + '/' + (type || 'generic'));
        console.log('    uuid=teldus:' + device.id);
        console.log('    perform: off, on');
        console.log('    name: ' + device.name);
        console.log('    status: ' + (device.online === '1' ? 'present' : 'absent'));
        console.log('    info:');
        if (type === 'dimmer') console.log('      dimmer: ' + Math.round((1-(255 - device.statevalue)/255)*100) + '%');
        console.log('');
      };
    };

    console.log('devices: '); console.log(devices); console.log(''); console.log('');
    for (i = 0; i < devices.length; i++) {
      if (devices[i].type === 'device') cloud.getDeviceInfo(devices[i], f(i, devices[i], 'getDeviceInfo'));
    }
  });
}).on('error', function(err) {
  console.log('background error: ' + err.message);
});

{'fraction_non_alphanumeric': 0.20508426163953156, 'fraction_numerical': 0.004284490145672665, 'mean_word_length': 2.444663059517954, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2686470', 'n_tokens_mistral': 2354, 'n_tokens_neox': 2280, 'n_words': 499}