65 lines
2.8 KiB
JavaScript
65 lines
2.8 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const MqttDispatcher_1 = require("./MqttDispatcher");
|
|
const AHomegearItem_1 = require("./AHomegearItem");
|
|
const Export_1 = require("./Export");
|
|
const WINDOW_OPEN_TEMPERATURE = 4.5;
|
|
class MaxThermostat extends AHomegearItem_1.AHomegearItem {
|
|
// Thermostat: homegear/instance1/set/3/1/SET_TEMPERATURE
|
|
getInTopic() {
|
|
return this.temperatureTopic;
|
|
}
|
|
exportItem() {
|
|
return Export_1.ThermostatExport(this.itemId, this.label, this.temperatureTopic, this.temperatureFeedbackTopic);
|
|
}
|
|
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
|