Files
dispatcher_ng/dist/MaxThermostat.js
2018-04-07 09:59:38 +02:00

90 lines
4.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const MqttDispatcher_1 = require("./MqttDispatcher");
const AHomegearItem_1 = require("./AHomegearItem");
// import { MaxWindowContact } from './MaxWindowContact';
const Export_1 = require("./Export");
const DISABLED_TEMPERATURE = 5.0;
class MaxThermostat extends AHomegearItem_1.AHomegearItem {
// Thermostat: homegear/instance1/set/3/1/SET_TEMPERATURE
getInTopic() {
return this.commandTopic;
}
exportItem() {
return Export_1.ThermostatExport(this.itemId, this.label, this.temperatureTopic, this.temperatureFeedbackTopic, this.presetTemperatureTopic, this.presetTemperatureFeedbackTopic);
}
constructor(floor, room, item, label, hmId, hardDisablers) {
super(floor, room, item, label, hmId);
this.temperatureTopic = `${this.topicFirstPart}/temperature`;
this.temperatureFeedbackTopic = `${this.topicFirstPart}/temperature/feedback`;
this.presetTemperatureTopic = `${this.topicFirstPart}/presetTemperature`;
this.presetTemperatureFeedbackTopic = `${this.topicFirstPart}/presetTemperature/feedback`;
this.deviceFeedbackTopic = `${this.deviceTopicPre}/1/SET_TEMPERATURE`;
this.actionTopic = `${this.actionTopicPre}/1/SET_TEMPERATURE`;
this.commandTopic = `${this.topicFirstPart}/command`;
this.subscribeTopics = [
this.temperatureTopic,
this.presetTemperatureTopic,
this.deviceFeedbackTopic,
this.commandTopic
];
this.hardDisabled = false;
this.hardDisablerMap = {};
hardDisablers.forEach((hardDisabler) => {
this.subscribeTopics.push(hardDisabler.getStateFeedbackTopic());
this.hardDisablerMap[hardDisabler.getStateFeedbackTopic()] = { disabler: hardDisabler, state: 'unknown' };
});
}
setPresetTemperature(presetTemperature) {
this.presetTemperature = presetTemperature;
}
startFunc() {
MqttDispatcher_1.mqttHandler.send(this.presetTemperatureTopic, `${this.presetTemperature}`);
}
processMessage(topic, payload) {
let setTemperature = false;
if (topic == this.temperatureTopic) {
this.temperature = parseFloat(payload);
setTemperature = true;
}
else if (topic == this.commandTopic) {
if (payload == 'ON') {
this.temperature = this.presetTemperature;
}
else if (payload == 'OFF') {
this.temperature = DISABLED_TEMPERATURE;
}
setTemperature = true;
}
else if (topic == this.presetTemperatureTopic) {
this.presetTemperature = parseFloat(payload);
MqttDispatcher_1.mqttHandler.send(this.presetTemperatureFeedbackTopic, `${this.presetTemperature}`);
}
else if (topic == this.deviceFeedbackTopic) {
// this.temperature = parseFloat(payload)
setTemperature = false;
}
else if (topic in this.hardDisablerMap) {
this.hardDisablerMap[topic].state = this.hardDisablerMap[topic].disabler.transform(payload);
this.hardDisabled = false;
Object.values(this.hardDisablerMap).forEach((w) => {
if (w.state == 'DISABLE') {
this.hardDisabled = true;
}
});
setTemperature = true;
}
if (setTemperature) {
if (!this.hardDisabled) {
MqttDispatcher_1.mqttHandler.send(this.temperatureFeedbackTopic, `${this.temperature}`);
MqttDispatcher_1.mqttHandler.send(this.actionTopic, `${this.temperature}`);
}
else {
MqttDispatcher_1.mqttHandler.send(this.temperatureFeedbackTopic, `${DISABLED_TEMPERATURE}`);
MqttDispatcher_1.mqttHandler.send(this.actionTopic, `${DISABLED_TEMPERATURE}`);
}
}
}
}
exports.MaxThermostat = MaxThermostat;
//# sourceMappingURL=MaxThermostat.js.map