SimpleTopicSwitchItem added, Regallicht changed
This commit is contained in:
56
dist/SimpleTopicSwitchItem.js
vendored
Normal file
56
dist/SimpleTopicSwitchItem.js
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
"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, 'true');
|
||||
}
|
||||
else {
|
||||
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'false');
|
||||
}
|
||||
this.oldState = this.state;
|
||||
}
|
||||
break;
|
||||
}
|
||||
this.emit('somethingChanged');
|
||||
}
|
||||
}
|
||||
exports.SimpleTopicSwitchItem = SimpleTopicSwitchItem;
|
||||
//# sourceMappingURL=SimpleTopicSwitchItem.js.map
|
Reference in New Issue
Block a user