84 lines
3.8 KiB
JavaScript
84 lines
3.8 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.temperatureTopic;
|
|
}
|
|
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' };
|
|
});
|
|
}
|
|
processMessage(topic, payload) {
|
|
let setTemperature = false;
|
|
if (topic == this.temperatureTopic) {
|
|
this.temperature = parseFloat(payload);
|
|
setTemperature = true;
|
|
}
|
|
else if (topic == this.commandTopic) {
|
|
if (payload == 'START') {
|
|
this.temperature = this.presetTemperature;
|
|
}
|
|
else {
|
|
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
|