50 lines
2.0 KiB
JavaScript
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
|