Files
dispatcher_ng/dist/TimerAdaptor.js
Wolfgang Hottgenroth 3a8dd1b577 typescriptifying completed
2018-01-09 17:40:11 +01:00

50 lines
2.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const AItem_1 = require("./AItem");
const logger = require("./log");
const MqttDispatcher_1 = require("./MqttDispatcher");
class TimerAdaptor extends AItem_1.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';
MqttDispatcher_1.mqttHandler.send(this.actionStateTopic, this.state, true);
this.timer = setTimeout(() => {
logger.info(`timer ${this.itemId} elapsed`);
this.state = 'OFF';
MqttDispatcher_1.mqttHandler.send(this.actionStateTopic, this.state, true);
}, (this.delay * 1000));
break;
case 'LONG_END':
if (this.timer != null) {
clearTimeout(this.timer);
}
if (this.state == 'OFF') {
this.state = 'ON';
}
else {
this.state = 'OFF';
}
MqttDispatcher_1.mqttHandler.send(this.actionStateTopic, this.state, true);
break;
}
break;
}
}
}
exports.TimerAdaptor = TimerAdaptor;
//# sourceMappingURL=TimerAdaptor.js.map