timer handling
This commit is contained in:
51
src/TimerAdaptor.js
Normal file
51
src/TimerAdaptor.js
Normal file
@ -0,0 +1,51 @@
|
||||
let AItem = require('./AItem')
|
||||
let logger = require('./log')
|
||||
let mqtt = require('./mqttHandler');
|
||||
|
||||
|
||||
class TimerAdaptor extends AItem {
|
||||
constructor(floor, room, item, delay) {
|
||||
super(floor, room, item);
|
||||
this.actionStateTopic = `${this.topicFirstPart}/state`;
|
||||
this.inTopic = `${this.topicFirstPart}/timerIn`;
|
||||
this.subscribeTopics = [ this.inTopic ];
|
||||
this.state = 'OFF';
|
||||
this.delay = delay;
|
||||
this.timer = null;
|
||||
}
|
||||
|
||||
processMessage(topic, payload) {
|
||||
switch (topic) {
|
||||
case this.inTopic:
|
||||
switch (payload) {
|
||||
case 'SHORT':
|
||||
if ((this.state == 'ON') && (this.timer != null)) {
|
||||
clearTimeout(this.timer);
|
||||
}
|
||||
this.state = 'ON';
|
||||
mqtt.send(this.actionStateTopic, this.state, true);
|
||||
this.timer = setTimeout(() => {
|
||||
this.state = 'OFF';
|
||||
mqtt.send(this.actionStateTopic, this.state, true);
|
||||
}, (this.delay * 1000));
|
||||
break;
|
||||
case 'LONG_END':
|
||||
clearTimeout(this.timer);
|
||||
if (this.state == 'OFF') {
|
||||
this.state = 'ON';
|
||||
this.overwrite = true;
|
||||
} else {
|
||||
this.state = 'OFF';
|
||||
this.overwrite = false;
|
||||
}
|
||||
mqtt.send(this.actionStateTopic, this.state, true);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = TimerAdaptor;
|
||||
|
@ -11,6 +11,7 @@ let M433SwitchItem = require('./M433SwitchItem');
|
||||
let HomematicFourButtonThing = require('./HomematicFourButtonThing');
|
||||
let HomematicFourButtonSingleItem = require('./HomematicFourButtonSingleItem');
|
||||
let DimmerAdaptor = require('./DimmerAdaptor');
|
||||
let TimerAdaptor = require('./TimerAdaptor');
|
||||
let Forwarder = require('./Forwarder');
|
||||
|
||||
|
||||
@ -22,7 +23,7 @@ deskLight.start();
|
||||
|
||||
let testFourButton = new HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [
|
||||
new HomematicFourButtonSingleItem('button1', 'dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'),
|
||||
new HomematicFourButtonSingleItem('button2', 'test/button/2'),
|
||||
new HomematicFourButtonSingleItem('button2', 'dispatcher_ng/items/Gnd/Hallway/DeskLight/timerIn'),
|
||||
new HomematicFourButtonSingleItem('button3', 'test/button/3'),
|
||||
new HomematicFourButtonSingleItem('button4', 'test/button/4')
|
||||
]);
|
||||
@ -31,6 +32,9 @@ testFourButton.start();
|
||||
let testDimmerAdaptor = new DimmerAdaptor('Gnd', 'Hallway', 'Testlight');
|
||||
testDimmerAdaptor.start();
|
||||
|
||||
let testTimerAdaptor = new TimerAdaptor('Gnd', 'Hallway', 'DeskLight', 10);
|
||||
testTimerAdaptor.start();
|
||||
|
||||
let testLight = new HomematicDimmerItemClass('Gnd', 'Hallway', 'Testlight', 8);
|
||||
testLight.start();
|
||||
|
||||
|
Reference in New Issue
Block a user