typescriptifying

This commit is contained in:
Wolfgang Hottgenroth
2018-01-09 16:36:14 +01:00
parent 9e39d74084
commit 8d85314fc9
21 changed files with 372 additions and 182 deletions

53
dist/HomematicFourButtonThing.js vendored Normal file
View File

@ -0,0 +1,53 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const logger = require("./log");
const MqttDispatcher_1 = require("./MqttDispatcher");
const AHomematicItem_1 = require("./AHomematicItem");
class HomematicFourButtonSingleItem {
constructor(actionTopic) {
this.actionTopic = actionTopic;
}
processMessage(topic, payload) {
switch (topic) {
case 'PRESS_SHORT':
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'SHORT', true);
break;
case 'PRESS_LONG':
case 'PRESS_CONT':
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'LONG_HOLD', true);
break;
case 'PRESS_LONG_RELEASE':
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'LONG_END', true);
break;
default:
logger.warn(`HM4BSI: no handling available for ${topic}`);
break;
}
}
}
exports.HomematicFourButtonSingleItem = HomematicFourButtonSingleItem;
class HomematicFourButtonThing extends AHomematicItem_1.AHomematicItem {
constructor(floor, room, item, hmId, itemObjs) {
super(floor, room, item, hmId);
this.itemObjs = itemObjs;
if (this.itemObjs.length != 4) {
throw new Error('itemObjs for HomematicFourButtonThing must have four elements');
}
this.subscribeTopics = [
`${this.deviceTopicPre}/#`
];
}
processMessage(topic, payload) {
logger.info(`HM4B: ${topic}, ${payload}`);
let buttonRelatedPart = topic.substring(this.deviceTopicPre.length + 1);
let buttonIdx = parseInt(buttonRelatedPart.substring(0, buttonRelatedPart.indexOf('/')));
if (buttonIdx >= 1 && buttonIdx <= 4) {
this.itemObjs[buttonIdx - 1].processMessage(buttonRelatedPart.substring(buttonRelatedPart.indexOf('/') + 1), payload);
}
else {
logger.warn(`HM4B: no handling available for ${topic}`);
}
}
}
exports.HomematicFourButtonThing = HomematicFourButtonThing;
//# sourceMappingURL=HomematicFourButtonThing.js.map