"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const MqttDispatcher_1 = require("./MqttDispatcher"); const AHomegearItem_1 = require("./AHomegearItem"); const Export_1 = require("./Export"); class HomematicSwitchItem extends AHomegearItem_1.AHomegearItem { getLabel() { return this.label; } getRoom() { return this.room; } getStateTopic() { return this.stateTopic; } getStateFeedbackTopic() { return this.stateFeedbackTopic; } getState() { return this.state; } constructor(floor, room, item, label, hmId, partId = 1, type = 'bulb') { super(floor, room, item, label, hmId); this.partId = partId; this.stateTopic = `${this.topicFirstPart}/state`; this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`; this.deviceFeedbackTopic = `${this.deviceTopicPre}/${this.partId}/STATE`; this.actionTopic = `${this.actionTopicPre}/${this.partId}/STATE`; this.subscribeTopics = [ this.stateTopic, this.deviceFeedbackTopic ]; this.state = 'OFF'; this.oldState = undefined; this.type = type; } exportItem() { return Export_1.SwitchExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type); } processMessage(topic, payload) { switch (topic) { case this.stateTopic: this.state = payload; MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state); if (this.state != this.oldState) { if (this.state == 'ON') { MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'true'); } else { MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'false'); } this.oldState = this.state; } break; case this.deviceFeedbackTopic: if (payload == 'true') { this.state = 'ON'; } else { this.state = 'OFF'; } this.oldState = this.state; MqttDispatcher_1.mqttHandler.send(this.stateFeedbackTopic, this.state); break; } this.emit('somethingChanged'); } } exports.HomematicSwitchItem = HomematicSwitchItem; //# sourceMappingURL=HomematicSwitchItem.js.map