touch switch support

This commit is contained in:
Wolfgang Hottgenroth
2018-01-31 16:13:44 +01:00
parent 409ab71365
commit 72516fac28
4 changed files with 163 additions and 16 deletions

51
dist/TouchSwitchMultiButtonThing.js vendored Normal file
View File

@ -0,0 +1,51 @@
"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 (topic) {
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, hmId, 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.substring(0, buttonRelatedPart.indexOf('/')));
if (buttonIdx >= 1 && buttonIdx <= this.itemObjs.length) {
this.itemObjs[buttonIdx - 1].processMessage(buttonRelatedPart.substring(buttonRelatedPart.indexOf('/') + 1), payload);
}
else {
logger.warn(`TSMBT: no handling available for ${topic}`);
}
}
}
exports.TouchSwitchMultiButtonThing = TouchSwitchMultiButtonThing;
//# sourceMappingURL=TouchSwitchMultiButtonThing.js.map