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.
|
|
|
var core = (room, light) => {
|
|
|
|
var o = {
|
|
|
|
NoPeopleDelayTime: 1000 * 10,
|
|
|
|
LastOnTime: 0,
|
|
|
|
LastOffTime: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
setInterval(()=>{
|
|
|
|
if(room.state != light.state){
|
|
|
|
room.state = light.state;
|
|
|
|
}
|
|
|
|
room.LastSwiTime = light.LastSwiTime;
|
|
|
|
}, 50);
|
|
|
|
|
|
|
|
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;
|