52 lines
2.1 KiB
JavaScript
52 lines
2.1 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 TouchSwitchButtonSingleItem {
|
|
constructor(actionTopic) {
|
|
this.actionTopic = actionTopic;
|
|
}
|
|
processMessage(topic, payload) {
|
|
switch (payload) {
|
|
case 'SHORT':
|
|
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'SHORT', true);
|
|
break;
|
|
case 'LONG_BEGIN':
|
|
case 'LONG_CONT':
|
|
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'LONG_HOLD', true);
|
|
break;
|
|
case 'LONG_END':
|
|
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'LONG_END', true);
|
|
break;
|
|
default:
|
|
logger.warn(`TWBSI: no handling available for ${topic}`);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
exports.TouchSwitchButtonSingleItem = TouchSwitchButtonSingleItem;
|
|
class TouchSwitchMultiButtonThing extends AItem_1.AItem {
|
|
constructor(floor, room, item, itemObjs) {
|
|
super(floor, room, item, '');
|
|
this.itemObjs = itemObjs;
|
|
this.deviceTopicPre = `IoT/TouchSwitch/${this.floor}/${this.room}/${this.item}`;
|
|
this.subscribeTopics = [
|
|
`${this.deviceTopicPre}/#`
|
|
];
|
|
}
|
|
processMessage(topic, payload) {
|
|
logger.info(`TSMBT: ${topic}, ${payload}`);
|
|
let buttonRelatedPart = topic.substring(this.deviceTopicPre.length + 1);
|
|
let buttonIdx = parseInt(buttonRelatedPart);
|
|
logger.info(`TSMBT: pre: ${this.deviceTopicPre}, buttonRelatedPart: ${buttonRelatedPart}, buttonIdx: ${buttonIdx}`);
|
|
if (buttonIdx >= 1 && buttonIdx <= this.itemObjs.length) {
|
|
this.itemObjs[buttonIdx - 1].processMessage('-', payload);
|
|
}
|
|
else {
|
|
logger.warn(`TSMBT: no handling available for ${topic}`);
|
|
}
|
|
}
|
|
}
|
|
exports.TouchSwitchMultiButtonThing = TouchSwitchMultiButtonThing;
|
|
//# sourceMappingURL=TouchSwitchMultiButtonThing.js.map
|