"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const logger = require("./log"); const MqttDispatcher_1 = require("./MqttDispatcher"); const AItem_1 = require("./AItem"); class RelayBoxThing extends AItem_1.AItem { constructor(floor, room, item, deviceCommandTopic, deviceStatusTopic, itemNames) { super(floor, room, item, ''); this.itemNames = itemNames; this.deviceCommandTopic = deviceCommandTopic; this.deviceStatusTopic = deviceStatusTopic; this.stateTopicPre = `${this.topicFirstPart}/state`; this.subscribeTopics = [ `${this.deviceStatusTopic}`, `${this.stateTopicPre}/#` ]; } processMessage(topic, payload) { // logger.info(`RT: ${topic}, ${payload}`) if (topic == this.deviceStatusTopic) { logger.info(`RT: status received`); let status = JSON.parse(payload); let statusParsed = JSON.stringify(status); logger.info(`RT: status parsed: ${statusParsed}`); logger.info(`RT: device: ${status.metadata.device}`); logger.info(`RT: uptime: ${status.data.uptime}`); for (let i = 0; i < this.itemNames.length; i++) { logger.info(`RT: state: ${status.data.switchstatus[i].state}`); logger.info(`RT: feedb: ${status.data.switchstatus[i].feedbackState}`); logger.info(`RT: confl: ${status.data.switchstatus[i].stateConflict}`); } } else { logger.info(`RT: ${topic}, ${payload}`); let thingRelatedPart = topic.substring(this.stateTopicPre.length + 1); let itemIdx = parseInt(thingRelatedPart); logger.info(`RT: pre: ${this.stateTopicPre}, thingRelatedPart: ${thingRelatedPart}, itemIdx: ${itemIdx}`); if (itemIdx >= 0 && itemIdx < this.itemNames.length) { if (payload == 'ON') { MqttDispatcher_1.mqttHandler.send(this.deviceCommandTopic, `switch ${itemIdx} on`); } else { MqttDispatcher_1.mqttHandler.send(this.deviceCommandTopic, `switch ${itemIdx} off`); } } else { logger.warn(`RT: no handling available for ${topic}`); } } } } exports.RelayBoxThing = RelayBoxThing; //# sourceMappingURL=RelayBox.js.map