42 lines
1.7 KiB
JavaScript
42 lines
1.7 KiB
JavaScript
"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`);
|
|
}
|
|
else {
|
|
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
|