<commit_before>const log = require('./logger.js').create('LOCK DRIVER');

class LockDriver {
    constructor(lock, sensor){
        this.lock = lock;
        this.sensor = sensor;
        this.sensor.on('close', this.onDoorClose.bind(this));
        this.sensor.on('open', this.onDoorOpen.bind(this));
        this.armed = false;
        
        this.lockTimeout = null;
    }
    
    Lock(){
        this.lock.Lock();
        log.write('Locked');
        if(this.armed){
            this.Disarm();
        }
    }
    
    Unlock(){
        this.lock.Unlock();
        log.write('Unlocked');
    }
    
    //auto lock when door is closed
    Arm(){
        this.armed = true;
        log.write('Armed');
    }
    
    Disarm(){
        this.armed = false;
        log.write('Disarmed');
    }
    
    onDoorClose(){
        if(this.armed){
            this.lockTimeout = setTimeout(() => {
                this.Lock();
            }, 5000);
        }
    }
    
    onDoorOpen(){
        clearTimeout(this.lockTimeout);
    }
}

module.exports = LockDriver;<commit_msg>Autolock delay to 3 sec<commit_after>const log = require('./logger.js').create('LOCK DRIVER');

class LockDriver {
    constructor(lock, sensor){
        this.lock = lock;
        this.sensor = sensor;
        this.sensor.on('close', this.onDoorClose.bind(this));
        this.sensor.on('open', this.onDoorOpen.bind(this));
        this.armed = false;
        
        this.lockTimeout = null;
    }
    
    Lock(){
        this.lock.Lock();
        log.write('Locked');
        if(this.armed){
            this.Disarm();
        }
    }
    
    Unlock(){
        this.lock.Unlock();
        log.write('Unlocked');
    }
    
    //auto lock when door is closed
    Arm(){
        this.armed = true;
        log.write('Armed');
    }
    
    Disarm(){
        this.armed = false;
        log.write('Disarmed');
    }
    
    onDoorClose(){
        if(this.armed){
            this.lockTimeout = setTimeout(() => {
                this.Lock();
            }, 3000);
        }
    }
    
    onDoorOpen(){
        clearTimeout(this.lockTimeout);
    }
}

module.exports = LockDriver;
{'fraction_non_alphanumeric': 0.15092592592592594, 'fraction_numerical': 0.004166666666666667, 'mean_word_length': 1.5942376950780313, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1521640', 'n_tokens_mistral': 674, 'n_tokens_neox': 661, 'n_words': 107}