This commit is contained in:
Wolfgang Hottgenroth
2018-01-31 21:25:17 +01:00
3 changed files with 11 additions and 8 deletions

View File

@ -8,7 +8,7 @@ class TouchSwitchButtonSingleItem {
this.actionTopic = actionTopic;
}
processMessage(topic, payload) {
switch (topic) {
switch (payload) {
case 'SHORT':
MqttDispatcher_1.mqttHandler.send(this.actionTopic, 'SHORT', true);
break;
@ -30,7 +30,7 @@ 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.deviceTopicPre = `IoT/TouchSwitch/${this.floor}/${this.room}/${this.item}`;
this.subscribeTopics = [
`${this.deviceTopicPre}/#`
];
@ -38,9 +38,10 @@ class TouchSwitchMultiButtonThing extends AItem_1.AItem {
processMessage(topic, payload) {
logger.info(`TSMBT: ${topic}, ${payload}`);
let buttonRelatedPart = topic.substring(this.deviceTopicPre.length + 1);
let buttonIdx = parseInt(buttonRelatedPart.substring(0, buttonRelatedPart.indexOf('/')));
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(buttonRelatedPart.substring(buttonRelatedPart.indexOf('/') + 1), payload);
this.itemObjs[buttonIdx - 1].processMessage('-', payload);
}
else {
logger.warn(`TSMBT: no handling available for ${topic}`);

1
dist/main.js vendored
View File

@ -119,6 +119,7 @@ let bedRoomWolfgangBedLight = new HueColorBulbItem_1.HueColorBulbItem('1st', 'Be
bedRoomWolfgangBedLight.start();
allLabeledItems.push(bedRoomWolfgangBedLight);
let touchSwitchMultiButtonThing = new TouchSwitchMultiButtonThing_1.TouchSwitchMultiButtonThing('1st', 'Bedroom', 'Wolfgang', [new TouchSwitchMultiButtonThing_1.TouchSwitchButtonSingleItem(bedRoomWolfgangBedLight.getStateTopic())]);
touchSwitchMultiButtonThing.start();
// Schlafzimmer Pattys Seite 13980756 24 1 13980753 24 1
let bedRoomPattysSide = new M433SwitchItem_1.M433SwitchItem('1st', 'BedRoom', 'PattysSide', 'Pattys Seite Schlafzimmer', '13980756 24 1', '13980753 24 1');
bedRoomPattysSide.start();

View File

@ -11,7 +11,7 @@ export class TouchSwitchButtonSingleItem {
}
processMessage(topic: string, payload: string) {
switch(topic) {
switch(payload) {
case 'SHORT':
mqttHandler.send(this.actionTopic, 'SHORT', true)
break
@ -36,7 +36,7 @@ export class TouchSwitchMultiButtonThing extends AItem {
constructor(floor: string, room: string, item: string, itemObjs: TouchSwitchButtonSingleItem[]) {
super(floor, room, item, '')
this.itemObjs = itemObjs
this.deviceTopicPre = `IoT/Touchswitch/${this.floor}/${this.room}/${this.item}`
this.deviceTopicPre = `IoT/TouchSwitch/${this.floor}/${this.room}/${this.item}`
this.subscribeTopics = [
`${this.deviceTopicPre}/#`
]
@ -45,9 +45,10 @@ export class TouchSwitchMultiButtonThing extends AItem {
processMessage(topic: string, payload: string) {
logger.info(`TSMBT: ${topic}, ${payload}`)
let buttonRelatedPart = topic.substring(this.deviceTopicPre.length+1)
let buttonIdx = parseInt(buttonRelatedPart.substring(0, buttonRelatedPart.indexOf('/')))
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(buttonRelatedPart.substring(buttonRelatedPart.indexOf('/')+1), payload)
this.itemObjs[buttonIdx-1].processMessage('-', payload)
} else {
logger.warn(`TSMBT: no handling available for ${topic}`)
}