<commit_before>/* jshint node: true */
'use strict';

var Q = require('q'),
    debug = require('debug')('zigbee-shepherd:init');

var af = require('../components/af'),
    loader = require('../components/loader');

var init = {};

init.setupShepherd = function (shepherd, callback) {
    var deferred = Q.defer(),
        controller = shepherd.controller,
        netInfo;

    debug('zigbee-shepherd booting...');

    shepherd.af = af(controller);
    controller.start().then(function () {
        return controller.request('ZDO', 'mgmtPermitJoinReq', { addrmode: 0x02, dstaddr: 0 , duration: 0, tcsignificance: 0 });
    }).then(function () {
        return shepherd._registerDev(controller.getCoord());
    }).then(function () {
        return loader.reload(shepherd);    // reload all devices from database
    }).then(function() {
        netInfo = controller.getNetInfo();

        debug('Loading devices from database done.');
        debug('zigbee-shepherd is up and ready.');
        
        debug('Network information:');
        debug(' >> State:      %s', netInfo.state);
        debug(' >> Channel:    %s', netInfo.channel);
        debug(' >> PanId:      %s', netInfo.panId);
        debug(' >> Nwk Addr:   %s', netInfo.nwkAddr);
        debug(' >> Ieee Addr:  %s', netInfo.ieeeAddr);
        debug(' >> Ext. PanId: %s', netInfo.extPanId);
    }).done(deferred.resolve, deferred.reject);

    /*
    Checking of each device disabled as it fails on large networks.
    We do this at a slower pace and with QoS within app_gateway

    Code:
    .then(function () {
        var devs = shepherd._devbox.exportAllObjs();

		var result = Q();
        var promises = devs.filter(function(dev){
			return dev.getNwkAddr() !== 0;
		}).forEach(function(dev) {
            result.then(Q(function(){return Q.delay(2000 + (Math.random() * 2000))}).then(controller.checkOnline(dev))) ;
        });
		
		return result;
    })
    */

    return deferred.promise.nodeify(callback);
};

module.exports = init;<commit_msg>unnecessary deferred<commit_after>/* jshint node: true */
'use strict';

var af = require('../components/af'),
    loader = require('../components/loader'),
    debug = require('debug')('zigbee-shepherd:init')

var init = {};

init.setupShepherd = function (shepherd, callback) {
    var controller = shepherd.controller,
        netInfo;

    debug('zigbee-shepherd booting...');

    shepherd.af = af(controller);
    return controller.start().then(function () {
        return controller.request('ZDO', 'mgmtPermitJoinReq', { addrmode: 0x02, dstaddr: 0 , duration: 0, tcsignificance: 0 });
    }).then(function () {
        return shepherd._registerDev(controller.getCoord());
    }).then(function () {
        return loader.reload(shepherd);    // reload all devices from database
    }).then(function() {
        netInfo = controller.getNetInfo();

        debug('Loading devices from database done.');
        debug('zigbee-shepherd is up and ready.');
        
        debug('Network information:');
        debug(' >> State:      %s', netInfo.state);
        debug(' >> Channel:    %s', netInfo.channel);
        debug(' >> PanId:      %s', netInfo.panId);
        debug(' >> Nwk Addr:   %s', netInfo.nwkAddr);
        debug(' >> Ieee Addr:  %s', netInfo.ieeeAddr);
        debug(' >> Ext. PanId: %s', netInfo.extPanId);
    }).nodeify(callback)
};

module.exports = init;
{'fraction_non_alphanumeric': 0.16406939135548368, 'fraction_numerical': 0.006174654513378418, 'mean_word_length': 2.826771653543307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '952010', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1015, 'n_words': 243}