Files
dispatcher_ng/dist/MaxEcoSwitch.js
Wolfgang Hottgenroth e88f9d225c fix MaxSwitch
2018-01-12 19:39:04 +01:00

56 lines
2.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const MqttDispatcher_1 = require("./MqttDispatcher");
const AHomematicItem_1 = require("./AHomematicItem");
class MaxEcoSwitch extends AHomematicItem_1.AHomematicItem {
constructor(floor, room, item, label, hmId, mainScene, ecoScene) {
super(floor, room, item, label, hmId);
this.mainButtonTopic = `${this.deviceTopicPre}/1/PRESS`;
this.ecoButtonTopic = `${this.deviceTopicPre}/2/PRESS`;
this.subscribeTopics = [this.mainButtonTopic, this.ecoButtonTopic];
this.mainTopic = mainScene.getStateTopic();
this.ecoTopic = ecoScene.getStateTopic();
this.state = 'OFF';
}
processMessage(topic, payload) {
switch (this.state) {
case 'OFF':
if (topic == this.mainButtonTopic) {
this.state = 'ON';
}
else if (topic == this.ecoButtonTopic) {
this.state = 'ECO';
}
break;
case 'ON':
if (topic == this.mainButtonTopic) {
this.state = 'OFF';
}
else if (topic == this.ecoButtonTopic) {
this.state = 'ECO';
}
break;
case 'ECO':
if (topic == this.mainButtonTopic) {
this.state = 'ON';
}
else if (topic == this.ecoButtonTopic) {
this.state = 'OFF';
}
break;
}
switch (this.state) {
case 'OFF':
MqttDispatcher_1.mqttHandler.send(this.mainTopic, 'OFF');
break;
case 'ON':
MqttDispatcher_1.mqttHandler.send(this.mainTopic, 'ON');
break;
case 'ECO':
MqttDispatcher_1.mqttHandler.send(this.ecoTopic, 'ON');
break;
}
}
}
exports.MaxEcoSwitch = MaxEcoSwitch;
//# sourceMappingURL=MaxEcoSwitch.js.map