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

View File

@ -0,0 +1,57 @@
import * as logger from './log'
import { mqttHandler } from './MqttDispatcher'
import { AItem } from './AItem'
export class TouchSwitchButtonSingleItem {
private actionTopic: string
constructor(actionTopic: string) {
this.actionTopic = actionTopic
}
processMessage(topic: string, payload: string) {
switch(topic) {
case 'SHORT':
mqttHandler.send(this.actionTopic, 'SHORT', true)
break
case 'LONG_BEGIN':
case 'LONG_CONT':
mqttHandler.send(this.actionTopic, 'LONG_HOLD', true)
break
case 'LONG_END':
mqttHandler.send(this.actionTopic, 'LONG_END', true)
break
default:
logger.warn(`TWBSI: no handling available for ${topic}`)
break
}
}
}
export class TouchSwitchMultiButtonThing extends AItem {
private itemObjs: TouchSwitchButtonSingleItem[]
private readonly deviceTopicPre: string
constructor(floor: string, room: string, item: string, hmId: number, itemObjs: TouchSwitchButtonSingleItem[]) {
super(floor, room, item, '')
this.itemObjs = itemObjs
this.deviceTopicPre = `IoT/Touchswitch/${this.floor}/${this.room}/${this.item}`
this.subscribeTopics = [
`${this.deviceTopicPre}/#`
]
}
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('/')))
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}`)
}
}
}