Files
dispatcher_ng/dist/SimpleTopicSwitchItem.js
2018-09-23 16:54:40 +02:00

56 lines
1.9 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const MqttDispatcher_1 = require("./MqttDispatcher");
const AItem_1 = require("./AItem");
const Export_1 = require("./Export");
class SimpleTopicSwitchItem extends AItem_1.AItem {
getLabel() {
return this.label;
}
getRoom() {
return this.room;
}
getStateTopic() {
return this.stateTopic;
}
getStateFeedbackTopic() {
return this.stateFeedbackTopic;
}
getState() {
return this.state;
}
constructor(floor, room, item, label, actionTopic) {
super(floor, room, item, label);
this.stateTopic = `${this.topicFirstPart}/state`;
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`;
this.actionTopic = actionTopic;
this.subscribeTopics = [
this.stateTopic
];
this.state = 'OFF';
this.oldState = undefined;
}
exportItem() {
return Export_1.SwitchExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type);
}
processMessage(topic, payload) {
switch (topic) {
case this.stateTopic:
this.state = payload;
MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state);
if (this.state != this.oldState) {
if (this.state == 'ON') {
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'ON');
}
else {
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'OFF');
}
this.oldState = this.state;
}
break;
}
this.emit('somethingChanged');
}
}
exports.SimpleTopicSwitchItem = SimpleTopicSwitchItem;
//# sourceMappingURL=SimpleTopicSwitchItem.js.map