Files
dispatcher_ng/dist/MaxThermostat.js
Wolfgang Hottgenroth f362c90b91 some changes
2018-01-15 21:24:53 +01:00

62 lines
2.6 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const MqttDispatcher_1 = require("./MqttDispatcher");
const AHomematicItem_1 = require("./AHomematicItem");
// import { SwitchExport, ExportType } from './Export'
const WINDOW_OPEN_TEMPERATURE = 4.5;
class MaxThermostat extends AHomematicItem_1.AHomematicItem {
// Thermostat: homegear/instance1/set/3/1/SET_TEMPERATURE
getInTopic() {
return this.temperatureTopic;
}
constructor(floor, room, item, label, hmId, windowContacts) {
super(floor, room, item, label, hmId);
this.temperatureTopic = `${this.topicFirstPart}/temperature`;
this.temperatureFeedbackTopic = `${this.topicFirstPart}/temperature/feedback`;
this.deviceFeedbackTopic = `${this.deviceTopicPre}/1/SET_TEMPERATURE`;
this.actionTopic = `${this.actionTopicPre}/1/SET_TEMPERATURE`;
this.subscribeTopics = [
this.temperatureTopic,
this.deviceFeedbackTopic
];
this.windowOpen = false;
this.windowContactMap = {};
windowContacts.forEach((windowContact) => {
this.subscribeTopics.push(windowContact.getStateFeedbackTopic());
this.windowContactMap[windowContact.getStateFeedbackTopic()] = { windowContact: windowContact, state: 'unknown' };
});
}
processMessage(topic, payload) {
let setTemperature = false;
if (topic == this.temperatureTopic) {
this.temperature = parseFloat(payload);
setTemperature = true;
}
else if (topic == this.deviceFeedbackTopic) {
// this.temperature = parseFloat(payload)
setTemperature = false;
}
else if (topic in this.windowContactMap) {
this.windowContactMap[topic].state = payload;
this.windowOpen = false;
Object.values(this.windowContactMap).forEach((w) => {
if (w.state == 'OPEN') {
this.windowOpen = true;
}
});
setTemperature = true;
}
if (setTemperature) {
if (!this.windowOpen) {
MqttDispatcher_1.mqttHandler.send(this.temperatureFeedbackTopic, `${this.temperature}`);
MqttDispatcher_1.mqttHandler.send(this.actionTopic, `${this.temperature}`);
}
else {
MqttDispatcher_1.mqttHandler.send(this.temperatureFeedbackTopic, `${WINDOW_OPEN_TEMPERATURE}`);
MqttDispatcher_1.mqttHandler.send(this.actionTopic, `${WINDOW_OPEN_TEMPERATURE}`);
}
}
}
}
exports.MaxThermostat = MaxThermostat;
//# sourceMappingURL=MaxThermostat.js.map