"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const logger = require("./log"); 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 { constructor(floor, room, item, label, hmId, hardDisablers) { super(floor, room, item, label, hmId); this.heatingMainFlag = false; 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, MaxThermostat.heatingMainSwitchTopic ]; this.hardDisabled = false; this.hardDisablerMap = {}; hardDisablers.forEach((hardDisabler) => { this.subscribeTopics.push(hardDisabler.getStateFeedbackTopic()); this.hardDisablerMap[hardDisabler.getStateFeedbackTopic()] = { disabler: hardDisabler, state: 'unknown' }; }); } // 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); } static exportHeatingMainSwitchItem() { return Export_1.HeatingMainSwitchExport(MaxThermostat.heatingMainSwitchTopic); } 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.heatingMainFlag) { this.temperature = this.presetTemperature; setTemperature = true; } else if (payload == 'OFF') { this.temperature = DISABLED_TEMPERATURE; setTemperature = true; } else if (payload == 'FORCE_ON') { this.temperature = this.presetTemperature; setTemperature = true; } } else if (topic == MaxThermostat.heatingMainSwitchTopic) { this.heatingMainFlag = (payload == 'ON'); logger.info(`${this.itemId} heating main: ${this.heatingMainFlag}`); if (!this.heatingMainFlag) { this.temperature = DISABLED_TEMPERATURE; MqttDispatcher_1.mqttHandler.send(this.temperatureFeedbackTopic, `${this.temperature}`); MqttDispatcher_1.mqttHandler.send(this.actionTopic, `${this.temperature}`); } } 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}`); } } } } MaxThermostat.heatingMainSwitchTopic = 'dispatcher_ng/items/heatingMainSwitch'; exports.MaxThermostat = MaxThermostat; //# sourceMappingURL=MaxThermostat.js.map