You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
610 B
30 lines
610 B
4 years ago
|
var core = (room, light) => {
|
||
|
var o = {
|
||
|
NoPeopleDelayTime: 1000 * 10,
|
||
|
LastOnTime: 0,
|
||
|
LastOffTime: 0,
|
||
|
};
|
||
|
|
||
|
room.on('peopleIn', ()=>{
|
||
|
if(room.num == 1){
|
||
|
light.on();
|
||
|
o.LastOnTime = new Date().valueOf();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
room.on('peopleOut', ()=>{
|
||
|
if(room.num == 0){
|
||
|
setTimeout(()=>{
|
||
|
if(room.num == 0){
|
||
|
light.off();
|
||
|
o.LastOffTime = new Date().valueOf();
|
||
|
}
|
||
|
}, o.NoPeopleDelayTime);
|
||
|
}
|
||
|
});
|
||
|
return o;
|
||
|
};
|
||
|
|
||
|
|
||
|
exports.core = core;
|